Discussion in 'PHP' started by shepherd, Apr 2, 2013.
What does the scope of variables means?
thumbtack clone | taskrabbit clone | agent anything clone
Scope refers to the visibility of variables.
In any language, we used variables so the visibility of the variable referred by Scope. Normally, Two kind of scope is there
1. Global scope
2. Local scope
If you define any variable within an function that variable having local scope and visibility within function only.
Scope of a variable is the lines of code from which it can be seen and/or manipulated. Scope can be thought of as visibility, because a variable's scope is where it is visible from. A variable declared within a function has scope only within that block. It is visible within any containing blocks. However, it should be noted that if a variable's name is reused in a nested declaration, then the outer variable loses scope within that block.
The scope of a variable means the area where you can use that particular variable, that means variable can be used only in these blocks where it is declared, variable are of two type one is local and another is global.
scope of variable in function may be defined as Local and Global.
Here is the output:
in function value of $name will show the output:Ram;
outside the function value of $name is :Sita;
scope of variable depends on the functions defined area ,
in which we use normally:
Separate names with a comma.