3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function hasort($arr) { $a = $b = array(); foreach($arr as $v => $k) $a[$k][] = $v; ksort($a); foreach($a as $v => $i) foreach($i as $k) $b[$k] = $v; return $b; } $a = array('a' => 10, 'z' => 10, 'c' => 10, 'b' => 11, 'd' => 10); $a = hasort($a); print_r($a); $a = array('a' => 10, 'z' => 10, 'c' => 10, 'b' => 11, 'd' => 10); asort($a, SORT_NUMERIC); var_dump($a);
based on fsQkS
Output for 7.0.0 - 7.1.0
Array ( [a] => 10 [z] => 10 [c] => 10 [d] => 10 [b] => 11 ) array(5) { ["a"]=> int(10) ["z"]=> int(10) ["c"]=> int(10) ["d"]=> int(10) ["b"]=> int(11) }
Output for 4.3.0 - 5.6.28
Array ( [a] => 10 [z] => 10 [c] => 10 [d] => 10 [b] => 11 ) array(5) { ["d"]=> int(10) ["a"]=> int(10) ["c"]=> int(10) ["z"]=> int(10) ["b"]=> int(11) }