3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function aff($t){ for($i=0;$i<count($t);$i++){ echo $t[$i]." "; } echo "<br />"; } function tablTrie($t){ for($i=0; $i < count($t)-1; $i++){ if($t[$i]>$t[$i+1]){return false;} } return true; } function trier(&$t){ if(!tablTrie($t)){trier2($t);} } function permuter (&$t,$i,$j){ $save=$t[$i]; $t[$i]=$t[$j]; $t[$j]=$save; } function trier2($t){ $u=0; for($i=0;$i<count($t)-1;$i++){ while($t[$i]>$t[$i+1]){ if($t[$i]<$t[$u]){$u=$u+1;} permuter($t,$u,$i); } } } //exemple d'appel $t=array(1,2,11,24,19,28,12,16,3,4,5,6,7,8,9,10); aff($t). "<br>"; trier($t); aff($t). "<br>"; ?>
based on SoRhR
Output for 5.3.20 - 7.3.0rc4
1 2 11 24 19 28 12 16 3 4 5 6 7 8 9 10 <br />1 2 11 24 19 28 12 16 3 4 5 6 7 8 9 10 <br />