PHP匿名函数

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-23 13:36:451256browse

1、匿名函数就是临时创建的没有名称的函数。
2、PHP从PHP5.3.0版本开始支持匿名函数。
3、PHP的匿名函数通过closures实现,常用于回调函数。

下面看一例子:

$my_array = array(1,2,3,4,5,6,7,8,9);
    print_r($my_array);
    echo "

";

    $new_array = array_filter($my_array, function($var){ return $var > 5;});
    print_r($new_array);
    echo "

";

?>

运行结果:


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