Anonymous functions in PHP

I ran into this and found it interesting. Someone has added support for anonymous functions in PHP.

With the patch you can now do stuff like:

$data = array("zoo", "orange", "car", "lemon", "apple");
usort($data, function($a, $b) { return strcmp($a, $b); });
var_dump($data); # data is sorted alphabetically 

Before you had to use a funky function generation call.

Tags:

Leave a Reply

Your email address will not be published.