3v4l.org

run code in 300+ PHP versions simultaneously
<?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 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Array ( [0] => 25 [1] => 45 [2] => 50 [3] => 98 )
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.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.3.11, 4.4.0 - 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.

preferences:
338.58 ms | 401 KiB | 460 Q