国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

PHP nested function and anonymous function scope issues
phpcn_u1582
phpcn_u1582 2017-05-18 10:45:34
0
1
737
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

reply all(1)
小葫蘆

That’s actually the case. When you call a function, the parameter you pass is actually a copy, and the value is copied, which is equivalent to another variable and has no relationship.
The same goes for anonymous functions. But if you want to use external variables in anonymous functions, they cannot be accessed.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template