3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $elem1 = array('name' => 'one' , 'score' => 123); $elem2 = array('name' => 'twei', 'score' => 235); $elem3 = array('name' => 'yoo', 'score' => 12); $data = [$elem1, $elem2, $elem3]; var_dump(sortByValue($data, 'score')); function sortByValue($array, $value) { $temp = []; foreach($array as $i => $elem) { $temp[$i] = $elem[$value]; } arsort($temp); var_dump($temp); $data = []; foreach($temp as $elem) { $data[] = $elem; } return $data; }
based on kvoO0
Output for 5.4.0 - 7.2.0
array(3) { [1]=> int(235) [0]=> int(123) [2]=> int(12) } array(3) { [0]=> int(235) [1]=> int(123) [2]=> int(12) }
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/Ye2SF on line 7
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/Ye2SF on line 7
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/Ye2SF on line 7
Process exited with code 255.