PHP variable
PHP variable is nothing but a container. In that container we store data. So we can say that PHP variable is a container that store information. Take a look at the picture to understand the PHP variable.
$var, $Var, $myVariable, $this_variable, $product, $_book, $__book, $this-variable
All of the above rule is right but in PHP we cannot write $this-variable, $_book, $__book type of variable. Now we try to write a variable example with PHP code.
<?php
$var=10;
echo $var;
?>
Save this code with any name and run. This will show 10. If you write same variable many times in PHP code segment, PHP just count the last variable information such as
<?php
$var=10;
$var=50;
$var=100;
echo $var;
?>
Try to run this code. PHP variable name is case sensitive. So try to write PHP code with consciously.
<?php
$var=200;
$Var=100;
echo $var;
echo $Var;
?>
It will show 200 and 100.
PHP variable naming convention:
Each variable has a name. To write variable name we need to follow some rules such as- PHP variables start with $ sign.
- A variable can constitute with letter, number, underscore or dash sign.
- PHP variable is case sensitive.
$var, $Var, $myVariable, $this_variable, $product, $_book, $__book, $this-variable
All of the above rule is right but in PHP we cannot write $this-variable, $_book, $__book type of variable. Now we try to write a variable example with PHP code.
<?php
$var=10;
echo $var;
?>
Save this code with any name and run. This will show 10. If you write same variable many times in PHP code segment, PHP just count the last variable information such as
<?php
$var=10;
$var=50;
$var=100;
echo $var;
?>
Try to run this code. PHP variable name is case sensitive. So try to write PHP code with consciously.
<?php
$var=200;
$Var=100;
echo $var;
echo $Var;
?>
It will show 200 and 100.
Comments
Post a Comment