3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $abc = array( 'rec_1' => array('fn'=>'Aron','ln'=>'Michaels'), 'rec_2' => array('fn'=>'Abbey','ln'=>'Drake'), 'rec_3' => array('fn'=>'Alice','ln'=>'Peterson')); /*function build_sorter($key) { return function ($a, $b) use ($key) { return strcmp($a[$key], $b[$key]); }; }*/ function sortit($a, $b , $key) { return strcmp($a[$key], $b[$key]); }; function mysort($key) { return sortit($a,$b,$key); } //usort($abc, build_sorter('ln')); usort($abc, mysort('ln')); foreach ($abc as $item) { echo strtoupper($item['ln']) . ', ' . $item['fn'] . "\n"; }
based on 8d4ca
Output for 5.3.0 - 7.2.0
Notice: Undefined variable: a in /in/tDvVM on line 20 Notice: Undefined variable: b in /in/tDvVM on line 20 Warning: usort() expects parameter 2 to be a valid callback, no array or string given in /in/tDvVM on line 27 MICHAELS, Aron DRAKE, Abbey PETERSON, Alice
Output for 5.2.5 - 5.2.17
Notice: Undefined variable: a in /in/tDvVM on line 20 Notice: Undefined variable: b in /in/tDvVM on line 20 Warning: usort(): Invalid comparison function in /in/tDvVM on line 27 MICHAELS, Aron DRAKE, Abbey PETERSON, Alice
Output for 5.0.4 - 5.2.4
Notice: Undefined variable: a in /in/tDvVM on line 20 Notice: Undefined variable: b in /in/tDvVM on line 20 Warning: usort(): Invalid comparison function. in /in/tDvVM on line 27 MICHAELS, Aron DRAKE, Abbey PETERSON, Alice
Output for 4.3.9 - 5.0.3
Notice: Undefined variable: a in /in/tDvVM on line 20 Notice: Undefined variable: b in /in/tDvVM on line 20 Warning: usort(): Invalid comparison function. in /in/tDvVM on line 27 MICHAELS, Aron DRAKE, Abbey PETERSON, Alice
Output for 4.3.0 - 4.3.8
Notice: Undefined variable: a in /in/tDvVM on line 20 Notice: Undefined variable: b in /in/tDvVM on line 20 PETERSON, Alice DRAKE, Abbey MICHAELS, Aron