Created
June 27, 2016 14:30
-
-
Save a1exlism/7ddaf3b3b207f5bef9579cf5ab97264c to your computer and use it in GitHub Desktop.
内部函数使用外部变量
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function array_traverse($arr) | |
{ | |
while (list($key, $value) = each($arr)) { | |
echo "$key => $value"."<br>"; | |
} | |
} | |
$arr = array(1,2,3,4); | |
function array_powN ($arr, $n) { | |
return (array_map(function ($val) use($n){ | |
// USE关键字, 可以在函数内使用函数之外的变量 JS就没这么多事... | |
return pow($val, $n); | |
}, $arr)); | |
} | |
$arr = array_powN($arr, 3); | |
array_traverse($arr); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment