Share on Google+Share on Google+

PHP Variables Types

This tutorial is the introduction of variables, naming convention of variables in PHP etc. You will also get some useful examples on variables and reference variables etc.

PHP Variables:

In PHP a variable is declared with a dollar sign followed by a name. The name of the variable is case sensitive means that $var and $Var are not equal and could contain different values.

In general almost every language follows the same rule and that is variable name should start with a letter or underscore, followed by any number or letter or underscore.

Any variable is defined by the value has assigned to it. Whatever value we assign to a particular variable, the data type of the variable changes to that only. It means in PHP there is no specific data type could be assigned to a variable, the data type is dynamic in nature.

PHP Variable Example:



$var=23;//valid and different from $Var

$12;//not valid

$_var;//valid and different from $Var and $var


PHP supports assign values by reference that means a new variable simply references to another variable. If we change the value of the first variable then it automatically reflects on the other reference variable. This kind of variables are most suitable when we need to change values in one function and the changes should reflect on each part of the programming.

$this is another kind of variable which is used in OOP PHP and we can not assign any value to it rather it is used to denote an object.





echo "Value of \$a is:".$a."<br/>";

echo "Value of \$ref is:".$ref."<br/>";


echo "Value of \$a is:".$a."<br/>";

echo "Value of \$ref is:".$ref."<br/>";


echo "Value of \$a is:".$a."<br/>";

echo "Value of \$ref is:".$ref."<br/>";



Value of $a is:33
Value of $ref is:33
Value of $a is:343
Value of $ref is:343
Value of $a is:33333333
Value of $ref is:33333333





Posted on: March 17, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.