Which version of php added anonymous functions

2020-02-12 03:00发布

In manual there is create_function function and you can pass result from that function to array_map, I thought that that is the only way to have something like anonymous functions and closures, but then I found that I can just put function like in javascript

array_map(function($a) {
    return $a + 1;
}, array(1, 2, 3, 4, 5));

In which version of php I can do this? Was this always there?

3条回答
Animai°情兽
2楼-- · 2020-02-12 03:47

Anonymous functions are available since PHP 5.3:

The key features of PHP 5.3.0 include:

查看更多
Ridiculous、
4楼-- · 2020-02-12 04:02

Closures (anonymous functions) were added in PHP 5.3.0

查看更多
登录 后发表回答