PHP Lambda Functions – Anonymous JS-like functions in PHP

PHP 5.3 brought some new interesting stuff, I know its out for a while, but I recently started to love this new functionality. Lambda functions are anonymous functions knows as closures and they are really similar to the closures in JavaScript.

The difference from JS is that variables in the closure don’t have access to variables from outside the function, unless they are brought into the closure by using the “use” keyword.

In following there is a nice example:

The “convertHexDecimal” splits the hex string (i.e. #23ef22) into its color components, converts them to decimal and returns an array(red, green, blue).