Home  >  Article  >  Backend Development  >  这样一段python,如何转成php实现?

这样一段python,如何转成php实现?

WBOY
WBOYOriginal
2016-06-06 20:15:421077browse

<code>def f1(f2):
    def f3():
        return f2</code>

就是函数里面的函数能访问到f2

php相关参考
https://segmentfault.com/q/1010000004588881?_ea=659685

回复内容:

<code>def f1(f2):
    def f3():
        return f2</code>

就是函数里面的函数能访问到f2

php相关参考
https://segmentfault.com/q/1010000004588881?_ea=659685

不懂php,不过你说的是“闭包”,详情自行搜索。

<code>
function c($msg){
  return function() use($msg) {
    echo $msg;
  };  
}

$a = c("hello world");
$a();

?></code>

<code><?php function f1($a){
    function f2($b){
        echo "$b\n";
    }
    f2($a);
}
f1(3);</code></code>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn