Closures

http://php.net/closures

<?php
$data 
= array(3,2,8,5,6,1,7,4,9);
usort($data
             function(
$a,$b) { 
                 if(
$a%2==$b%2) return $a>$b;
                 return (
$a%2) ? : -1;
             }
     );
foreach(
$data as $v) echo "$v ";
Output
2 4 6 8 1 3 5 7 9

<?php
$getClosure 
= function($v) {
    return function() use(
$v) {
        echo 
"Hello World: $v!\n";
    };
};

$closure $getClosure(2);
$closure();
Output
Hello World: 2!

Remember closures are early-binding

<?php
function getMsgFnc() {
    global 
$msg;
    return function() use (
$msg) {
        echo 
"Msg: {$msg}!<br/>\n";
    };
}

$GLOBALS['msg'] = "Hello";
$fnc getMsgFnc();
$fnc();
$GLOBALS['msg'] = "World";
$fnc();
Output
Msg: Hello!
Msg: Hello!

However, you can do this:

<?php
function getMsgFnc2() {
    global 
$msg;
    return function() use (&
$msg) {
        echo 
"Msg: {$msg}!<br/>\n";
    };
}

$GLOBALS['msg'] = "Hello";
$fnc getMsgFnc2();
$fnc();
$GLOBALS['msg'] = "World";
$fnc();
Output
Msg: Hello!
Msg: World!