Function inside a function.?

前端 未结 6 1842
野性不改
野性不改 2020-11-29 03:02

This code produces the result as 56.

function x ($y) {
    function y ($z) {
        return ($z*2);
    }

    return($y+3);
}

$y = 4;
$y = x($y)*y($y);
ech         


        
6条回答
  •  春和景丽
    2020-11-29 03:47

    (4+3)*(4*2) == 56
    

    Note that PHP doesn't really support "nested functions", as in defined only in the scope of the parent function. All functions are defined globally. See the docs.

提交回复
热议问题