+ 2
Can anyone explain it further Variables Scope ???
Variables Scope PHP variables can be declared anywhere in the script. The scope of a variable is the part of the script in which the variable can be referenced or used. I'm confusing to understand it I'm not finding difference between global and local??
1 Respuesta
+ 3
The difference is where the variables can be accessed.
If you create a function (say, cow) and set the variable $noise = 'moo' within that function. Now try to print out $noise from outside the function.
The rest of the program doesn't know about that variable.
Likewise, ask the variables defined outside of cow aren't there to use within cow unless they are passed as parameters.
Data separation like this is to avoid some really sneaky types of bugs, but it does take mind stretching to grasp at first.
Hope that helped...