Which version of php added anonymous functions

ぐ巨炮叔叔 提交于 2019-11-28 03:02:10

问题


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?


回答1:


Closures (anonymous functions) were added in PHP 5.3.0




回答2:


Anonymous functions are available since PHP 5.3:

The key features of PHP 5.3.0 include:

  • Lambda Functions and Closures



回答3:


PHP >5.3:

http://php.net/manual/en/functions.anonymous.php



来源:https://stackoverflow.com/questions/9148841/which-version-of-php-added-anonymous-functions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!