Home > Backend Development > PHP Tutorial > PHP匿名函数

PHP匿名函数

WBOY
Release: 2016-06-23 13:36:45
Original
1213 people have browsed it

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 "

";

?>

运行结果:


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