fork(1) download
  1. <?php
  2. function sorted($a){
  3. if(count($a)<2){
  4. return $a;
  5. } else {
  6. $l = $r = array();
  7.  
  8. for ($i=1; $i<count($a); $i++){
  9. if ($a[$i] < $a[0])
  10. $l[] = $a[$i];
  11. else
  12. $r[] = $a[$i];
  13. }
  14.  
  15. return array_merge(sorted($l), array($a[0]), sorted($r));
  16. }
  17. }
  18.  
  19. $a = array(11,1,23,45,7,12,4,6,8,43);
  20. print_r(sorted($a));
Success #stdin #stdout 0.02s 52480KB
stdin
Standard input is empty
stdout
Array
(
    [0] => 1
    [1] => 4
    [2] => 6
    [3] => 7
    [4] => 8
    [5] => 11
    [6] => 12
    [7] => 23
    [8] => 43
    [9] => 45
)