Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php inline callback

A quick question.

Is it possible to declare the callback function inline, in php? For example,

array_filter($input_array, "function($item) { $item['state'] != 0 }")
like image 687
jose Avatar asked Oct 11 '12 10:10

jose


2 Answers

Yes, after php 5.3, you could use anonymous function.

array_filter($input_array, function($item) { return $item['state'] != 0; });
like image 189
xdazz Avatar answered Oct 15 '22 02:10

xdazz


Sure it calls anonymous functions:

array_filter($input_array, function($item) { 
    return $item['state'] != 0;
});
like image 44
Denis Ermolin Avatar answered Oct 15 '22 02:10

Denis Ermolin