All variables in PHP start with a $ (dollar) sign followed by the name of the variable.A valid variable name starts with a letter (A-Z, a-z) or underscore (_), followed by any number of letters, numbers, or underscores.
If a variable name is more than one word, it can be separated with an underscore (for example $employee_code instead of $employeecode).'$' is a special variable that can not be assigned.
A variable can have a short name (like x and y) or a more descriptive name (age, carname, total_volume).
PHP variables Rules:
In a language such as C, C++, and Java the programmer must declare the name and type of the variable before use it. In PHP the type of the variable does not need to be declared before use it because types are associated with values rather than variables. As a result, a variable can change the type of its value as much as we want.
As previously mentioned you don't need to declare variables or their type before using them in PHP. In the following example, none of the variables are declared before they are used, the fact is $height is floating number and $width is an integer.
In PHP, variables can be declared anywhere in the script.The scope of a variable is the part of the script where the variable can be referenced/used.
PHP three different variable scopes:
We have already learned variables declared outside a function are global. They can be accessed anywhere in the program except within a function.
To use these variables inside a function the variables must be declared global in that function. To do this we use the global keyword before the variables.
PHP also stores all global variables in an array called $GLOBALS[index]. The index holds the name of the variable. This array is also accessible from within functions and can be used to update global variables directly.