3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $a1 = array(50,36,2,458568,34,6,34637,235,8,323,457,2488,56635,9,9554522); $a2 = array(); $maxidx = count($a1); while(count($a1) > 0){ $max = 0; for($i = 0; $i < $maxidx; $i++){ if(isset($a1[$i])){ if($a1[$i] >= $max){ $max = $i; } } } array_push($a2, $a1[$max]); unset($a1[$max]); } var_dump($a2);
based on 8m3q1
Output for 4.3.0 - 7.2.0
array(15) { [0]=> int(9554522) [1]=> int(56635) [2]=> int(2488) [3]=> int(457) [4]=> int(9) [5]=> int(323) [6]=> int(8) [7]=> int(235) [8]=> int(34637) [9]=> int(6) [10]=> int(34) [11]=> int(458568) [12]=> int(2) [13]=> int(36) [14]=> int(50) }