Function Scope
suggest changeA variable assigned inside a function is local to that function. It does not change a variable of the same name outside the function.
$number = 5;
function foo(){
$number = 10;
return $number;
}
echo foo(); // Prints 10
echo $number; // Prints 5. The assignment inside foo did not change this variable.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents