fork download
  1. <?php
  2. $a = array(4,1,3,2,5);
  3. $q = count($a);
  4. for ($i = 0; $i < $q; $i++){
  5. for ($j = 0; $j < ($q-1); $j++){
  6. $J = $a[$j];
  7. if ($a[$j]>$a[$j+1]){
  8. $a[$j] = $a[$j+1];
  9. $a[$j+1] = $J;
  10. }
  11. }
  12. }
  13. print_r($a);
Success #stdin #stdout 0.02s 52472KB
stdin
Standard input is empty
stdout
Array
(
    [0] => 1
    [1] => 2
    [2] => 3
    [3] => 4
    [4] => 5
)