3v4l.org

run code in 300+ PHP versions simultaneously
<?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"; }
Output for 8.3.0 - 8.3.6
Warning: Undefined variable $a in /in/tDvVM on line 20 Warning: Undefined variable $b in /in/tDvVM on line 20 Warning: Trying to access array offset on null in /in/tDvVM on line 15 Warning: Trying to access array offset on null in /in/tDvVM on line 15 Deprecated: strcmp(): Passing null to parameter #1 ($string1) of type string is deprecated in /in/tDvVM on line 15 Deprecated: strcmp(): Passing null to parameter #2 ($string2) of type string is deprecated in /in/tDvVM on line 15 Fatal error: Uncaught TypeError: usort(): Argument #2 ($callback) must be a valid callback, no array or string given in /in/tDvVM:27 Stack trace: #0 /in/tDvVM(27): usort(Array, 0) #1 {main} thrown in /in/tDvVM on line 27
Process exited with code 255.
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.18
Warning: Undefined variable $a in /in/tDvVM on line 20 Warning: Undefined variable $b in /in/tDvVM on line 20 Warning: Trying to access array offset on value of type null in /in/tDvVM on line 15 Warning: Trying to access array offset on value of type null in /in/tDvVM on line 15 Deprecated: strcmp(): Passing null to parameter #1 ($string1) of type string is deprecated in /in/tDvVM on line 15 Deprecated: strcmp(): Passing null to parameter #2 ($string2) of type string is deprecated in /in/tDvVM on line 15 Fatal error: Uncaught TypeError: usort(): Argument #2 ($callback) must be a valid callback, no array or string given in /in/tDvVM:27 Stack trace: #0 /in/tDvVM(27): usort(Array, 0) #1 {main} thrown in /in/tDvVM on line 27
Process exited with code 255.
Output for 8.0.0 - 8.0.30
Warning: Undefined variable $a in /in/tDvVM on line 20 Warning: Undefined variable $b in /in/tDvVM on line 20 Warning: Trying to access array offset on value of type null in /in/tDvVM on line 15 Warning: Trying to access array offset on value of type null in /in/tDvVM on line 15 Fatal error: Uncaught TypeError: usort(): Argument #2 ($callback) must be a valid callback, no array or string given in /in/tDvVM:27 Stack trace: #0 /in/tDvVM(27): usort(Array, 0) #1 {main} thrown in /in/tDvVM on line 27
Process exited with code 255.
Output for 7.4.0 - 7.4.33
Notice: Undefined variable: a in /in/tDvVM on line 20 Notice: Undefined variable: b in /in/tDvVM on line 20 Notice: Trying to access array offset on value of type null in /in/tDvVM on line 15 Notice: Trying to access array offset on value of type null in /in/tDvVM on line 15 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 7.3.32 - 7.3.33
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.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31
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.0.5, 5.1.0 - 5.1.6, 5.2.0 - 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 - 4.3.11, 4.4.0 - 4.4.9, 5.0.0 - 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

preferences:
299.95 ms | 402 KiB | 464 Q