3v4l.org

run code in 300+ PHP versions simultaneously
<?php $data = array( array("id"=>3, "name"=>"peter"), array("id"=>1, "name"=>"steve"), array("id"=>5, "name"=>"damian"), array("id"=>9, "name"=>"ethan") ); $c = function($key, $order = SORT_DESC) { return function($a, $b) use $key, $order { if ($order === SORT_ASC) $order = -1; else $order = 1; if (is_numeric($a[$key])) return $order* ($a[$key] - $b[$key]); if (is_string($a[$key])) return $order*strcmp($a[$key], $b[$key]); return 0; }; }; usort($data, $c("id")); print_r($data);
Output for 5.4.0 - 5.4.29
Parse error: syntax error, unexpected '$key' (T_VARIABLE), expecting '(' in /in/mJtiR on line 11
Process exited with code 255.
Output for 5.3.0 - 5.3.28
Parse error: syntax error, unexpected T_VARIABLE, expecting '(' in /in/mJtiR on line 11
Process exited with code 255.

preferences:
163.56 ms | 1395 KiB | 66 Q