3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function ascending_array($array){ if (!is_array($array)){ $array = explode(",", $array); } $new = array(); $flag = true; iter: $array = array_values($array); // recount array values with new offsets (isset($min["max"])) ? $min["value"] = $min["max"] : $min["value"] = $array[0]; $min["offset"] = 0; for ($i=0;$i<count($array);$i++){ if ($array[$i] < $min["value"]){ // redefine min values each time if statement executed $min["value"] = $array[$i]; $min["offset"] = $i; } if ($flag){ // execute only first time if ($array[$i] > $min["value"]){ // define max value from array $min["max"] = $array[$i]; } $flag = false; } if ($i === (count($array)-1)){ // last array element array_push($new,$min["value"]); unset($array[$min["offset"]]); } } if (count($array)!=0){ goto iter; } print_r($new); } $arr = array(50,25,98,45); print_r(ascending_array($arr)); // 25 45 50 98
Output for 5.3.0 - 7.1.0
Array ( [0] => 25 [1] => 45 [2] => 50 [3] => 98 )
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.2.17
Parse error: syntax error, unexpected ':' in /in/H1Hmj on line 11
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/H1Hmj on line 11
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/H1Hmj on line 11
Process exited with code 255.