Many of the beginners thinks that if $x = 1 (variable x = 1 ) that means $x is equal to 1 but that's not right.Here x is like a container which contains the number 1.
You might think that it is the same thing but its not, there is an " === " operator which will compare and tell if the variables are exactly same.And by exactly same it must be exactly same,like $var1="hello" and $var2="Hello" ,here both are hello but they are not the same,right now this might not be something of your interest but it'll be a big fact,worth looking into while we learn more.
So
So
Creating /Declaring PHP Variables
In PHP, a variable starts with the $ sign, followed by the name of the variable:
<?php
$txt = "Hello world!";
$x = 5;
$y = 10.5;?>
$txt = "Hello world!";
$x = 5;
$y = 10.5;?>
A variable can have a short name (like x and y or xy or yx) or a more descriptive name (age, carname, total_volume)
- A variable name cannot start with a number
- Variable names are case-sensitive ($age and $AGE are two different variables)
- A variable starts with the $ sign, followed by the name of the variable
- A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )
remember PHP variables are case sensitive.
so $var_X is not as the same as $var_x
so $var_X is not as the same as $var_x
Output Variables
<?php
$txt = "PHP";
echo "$txt is fun ";?>
or
$txt = "PHP";
echo "$txt is fun ";?>
or
<?php
$txt = "coding";
echo "I love $txt!";?>
The following example will produce the same output as the example above:
$txt = "coding";
echo "I love $txt!";?>
The following example will produce the same output as the example above:
<?php
$txt = "W3Schools.com";
echo "I love " . $txt . "!";
?>
Now for a simple math,
<?php
$x = 5;
$y = 4;
echo $x + $y;
?>
$x = 5;
$y = 4;
echo $x + $y;
?>





