I recently really wanted to us anonymous functions in PHP. Unfortunately my host is still on 5.2. I automatically thought this would work:
uasort($array, function($a, $b) {
return $a > $b;
});
Is this how they work? Simply passed in as an argument instead of a callback? The docs don’t say specifically that’s how they do, but I have a working knowledge of JavaScript’s anonymous functions, so I assumed they would.
Yes. You can use it in place of regular PHP callbacks.
Try this (in PHP 5.3):
How
call_user_func()works is it will accept any of the following:and now in PHP 5.3
My guess is that internal PHP functions user
call_user_func()for callbacks, and because it has support for anonymous functions, they will work just as well as other callbacks.