I’ll try to explain with an example…
Let’s say I have two different functions, and one of them has a defined variable. In the second function, I don’t wanna write the same variable again, can I simply use the variable from the first function in the second one WITHOUT redefining it in the second function?
Something like:
function a()
{
$var = "my variable";
}
function b()
{
echo $var;
}
Sorry if this questions is a bit silly, but I’m still a beginner =).
Sure you can do globals, but of PHP 5.3.0+ has anonymous functions, so you can also do closures:
Try it out at this Codepad example
or probably more useful:
Try it out at this Codepad example
From the docs: