3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function uasort_key(&$arr, $func) { return uksort($arr, function($a,$b) use(&$arr,$func) { return $func($arr[$a], $arr[$b], $a, $b); }); } function sort_me($a, $b, $ka = 0, $kb = 0) { return ($a < $b ? -1 : ($a > $b ? 1 : ($ka < $kb ? -1 : ($ka > $kb ? 1 : 0)) )); } $test_array = array(4,6,2,1,7,5,1,34,1,0,4); $test_array_uasort_key = $test_array; uasort_key($test_array_uasort_key, 'sort_me'); print_r($test_array_uasort_key);
based on 4QLit
Output for 7.0.6 - 7.2.0
Array ( [9] => 0 [3] => 1 [6] => 1 [8] => 1 [2] => 2 [0] => 4 [10] => 4 [5] => 5 [1] => 6 [4] => 7 [7] => 34 )
Output for 7.0.0 - 7.0.5
Array ( [9] => 0 [6] => 1 [3] => 1 [2] => 2 [0] => 4 [1] => 6 [10] => 4 [8] => 1 [5] => 5 [4] => 7 [7] => 34 )
Output for 5.3.21 - 5.6.28
Warning: uksort(): Array was modified by the user comparison function in /in/9uqO8 on line 6 Array ( [9] => 0 [3] => 1 [6] => 1 [8] => 1 [2] => 2 [0] => 4 [10] => 4 [5] => 5 [1] => 6 [4] => 7 [7] => 34 )