PHP nested function and anonymous function scope issues
phpcn_u1582
phpcn_u1582 2017-05-18 10:45:34
0
1
428
function a()
{
    $demi = '局部变量';
    b($demi);
}
function b($args)
{
    echo $args;
}
a();

All functions and classes in PHP have global scope and can be defined within a function and called outside, and vice versa.

Why can function b obtain the local variables of function a by passing parameters?

function tesxt()
{
    $var = 10;
    $echonumber = function($num) {
         echo $num;
    };
    $echonumber($var);
}
tesxt();

Similarly, why do anonymous functions also obtain variables of external functions by passing parameters?

phpcn_u1582
phpcn_u1582

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!