PHP 闭包使用

WBOY
Release: 2016-06-13 13:17:09
Original
944 people have browsed it

PHP 闭包应用

闭包的用法

?

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

?

?

使用外部变量

?

$name = '柒翼凌风';
$fun = function($age, $sex) use ($name) {
    echo sprintf('%s, age:%s, sex:%s', $name, $age, $sex);
};
$fun(25, '男');
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!