Home  >  Article  >  Backend Development  >  PHP 闭包使用

PHP 闭包使用

WBOY
WBOYOriginal
2016-06-13 10:38:57887browse

PHP 闭包应用

闭包的用法

?

$fun = function($agr, $agr2) {    echo sprintf('var1:%s, $var2:%s', $var1, $var2);};$fun(1,2);

?

?

使用外部变量

?

$name = '柒翼凌风';$fun = function($age, $sex) use ($name) {    echo sprintf('%s, age:%s, sex:%s', $name, $age, $sex);};$fun(25, '男');

?

?

?

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
Previous article:深入学习PHP配备Next article:php中兑现多进程