A variable is a named memory location in which we can store values for the particular program.In other words, Variable is a name of memory location and used to hold the value.
In PHP, a variable is created using $ symbol followed by variable name.
format: $variablename = value;
Rules for naming variable:
$a = "Study"; ---> Valid declaration
$_b = "Glance"; ---> Valid declaration
$3c = "Hello"; ---> Invalid declaration
$*d = 25; ---> Invalid declaration
$a = "Study";
$A = "Glance";
In PHP, We don't need to declare explicitly variable, when we assign any value to the variable that variable is declared automatically.
In PHP, We don't need to specify the type of variable because PHP is a loosely typed language. I.e. In loosely typed language no need to specify the type of variable because the variable automatically changes it's datatype based on the assigned value.
Example:
$str = "Study Glance"; //string type variable
$x = 250; //integer type variable
$y = 14.6; //float type variable
<html>
<head>
<title>Variables Demo</title>
</head>
<body bgcolor="#fff">
<h1>Variable Demonstration</h1>
<?php
$str = "Study Glance";
$x = 112;
$y = 45.12;
echo "String is : $str<br/>";
echo "Integer is : $x <br/>";
echo "Float is : $y <br/>";
?>
</body>
</html>