Loading...

PHP Variables


A variable is just like a container which holds the data in it. in php a variable is used to store the value of any data type like int, string, float etc.
in php a variable has a prefix '$'' symbol which is mandatory for declare or define a variable.
for example :-
$variable = value;
*  for declare or defining a string or int,float, variable in php :
*   for string or char in value we should use single('') or double quote("").
   like $msg = "hello world"; *   for numeric value we use value directly.
   like $num = 11;
                                                	
<?php
$msg = "hello world";
$num = 11;
$dec = 99.5;
echo $msg."<br>"
echo $num."<br>"
echo $dec."<br>"
?>
output :
hello world
11
99.5

Rule for variables


In php variables variable name should start with alphabet(letter) or underscore(_) only.
for example :
$msg;    //valid
$_msg;    //valid
php variable name can't start with digit, number or any special characters. which is invalid in php.
for example :
$1msg;    //invalid
$*msg;    //invalid

Variables are case sensitive


In php variables are case sensitive thats why $name is differ from $Name, $NAME etc.