--- title: Learn About Php Variables --- Variables are containers for storing data such as `strings`, `integers`, `boolean` values, `array` and objects. PHP follows certain rules for variable declarations such as: * The variable must begin with a dollar sign ($) Example: `php ` * The variable name can contain characters such as A-Z, a-z, 0-9, _ and ASCII characters from 127-255. Example: `php ` * The variable name can begin with underscore (_). Example: `php ` * The variable name must not begin with a number 0-9. Example: `php ` * The variable name is case sensitive. Example: "; echo $VAR; //Output Foo ?> PHP is a loosely typed language, hence we don't need to declare the data type of a variable when declaring the variable. Unlike Java or C. "; echo $var+$var2; //Output 9 ?> The variables can also be assigned by referencing. This allows two variables to refer to the same content. The `&` operator is placed before the variable that is to be referenced. Example : To have variable names set dynamically we use the variable variables. This can be particularly useful when there is a need to create multiple variables. Example : # Variable Scope Scope of variable refers to the places from where a variable is accessible. * Global scope is for the variables that are declared outside a function. These variables can be accessed from anywhere but not within a function. * Local scope is for the variables declared within a function that can not be accessed from anywhere outside the function. Example: To access global variables inside a function: # Static Variables Everytime a function is created all of its local variables are deleted. To retain the variable's last value we declare it `static`. Example :