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

WBOY
Release: 2016-06-06 20:15:42
Original
1092 people have browsed it

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

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

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

回复内容:

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

就是函数里面的函数能访问到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>
Copy after login

<code><?php function f1($a){
    function f2($b){
        echo "$b\n";
    }
    f2($a);
}
f1(3);</code></code>
Copy after login
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
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!