Learn PHP Variable

A variable is a memory location that hold data.Variable used to store data inside temporary .In PHP ,we declare variable using ($).
Syntax of desclaring a variable:

$variable="Any Value";   

PHP Variable to store string, integer and float

See the diffrent examples of variable decration:

$str="I am Akshay";  
echo "string is: $str 
; echo "integer value is: $a
; echo "float value is : $b
; ? >


string is: I am Akshay
integer value is: 220 
float value is: 41.6 

PHP add the values inside variables

echo $c;  



PHP case senstive Variables

Inside PHP variables are case sensitive that mean  $Name  and $NAME are two diffrent variables . I you use diffrent name or not the same variable name ,it will show you error . Shown below:

echo "My name is " . $color . "
; echo "My name is " . $NAME . "
; echo "My name is " . $naME. "
; ?>


My car is akshay
Notice: Undefined variable: NAME in C:\wamp\www\variable.php on line 4
My name is 
Notice: Undefined variable: naME in C:\wamp\www\variable.php on line 5
My name is 

PHP invalid Variables

Some variables are invalid inside PHP .That means PHP dont accept them and show error.

Shown Below:

$12c="hi there";//number in begining (invalid)  
$c12="hi there again ";//number after text (valid)  
$*data="hi there";//special symbol (invalid)  
echo "$12c 
; echo $c12; ?>


Parse error: syntax error, unexpected '4' (T_LNUMBER), expecting variable (T_VARIABLE)
 or '$' in C:\wamp\www\variableinvalid.php on line 2
hi there

 I Hope you understand the concept behind Variables . If yes continue to next lesson :)

Last Updated: 2018-07-06 12:32:44 By akshay


share_facebook share_twitter share_google_plus

Please Comment Here :