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

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 20:15:42
Original
1168 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:
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template