PHP variable in a program is used to store data, like a string of text, numbers, etc. Following are some important things to know about variables:
The variable can be declared as: $var_name = value.
In this example we have created two variables where first one has assigned with a string value and the second has assigned with a number.
Rules for Variable declaration:
PHP Variables Scope:
A variables declared within a function are considered as local variables to that function and has its scope only in that particular function means it cannot be accessed outside that function.
A variables declared outside a function are considered as global variables. To use this variable within a function we need to use the “global” keyword before the variable to refer to the global variable.
Normally, when a function terminates, all of its variables delete its values. But sometimes we want to store these values for further jobs. The variables which hold the values are called static variables. To do this we must use the keyword “static” in front of those variables.