Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which version of php added anonymous functions

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?

like image 814
jcubic Avatar asked Feb 05 '12 11:02

jcubic


1 Answers

Anonymous functions are available since PHP 5.3:

The key features of PHP 5.3.0 include:

  • Lambda Functions and Closures
like image 89
knittl Avatar answered Oct 05 '22 23:10

knittl