Bubble Sort

First attempt, sort without trace :

$a = [21, 3, 12, 4, 3, 7, 8, 17, 10, 2, ]
$b = [2, 3, 3, 4, 7, 8, 10, 12, 17, 21, ]

Second attempt, sort with a trace :

$a = [21, 3, 12, 4, 3, 7, 8, 17, 10, 2, ]
Pass: 0
21 3 12 4 3 7 8 17 10 2
3 21 12 4 3 7 8 17 10 2
3 12 21 4 3 7 8 17 10 2
3 12 4 21 3 7 8 17 10 2
3 12 4 3 21 7 8 17 10 2
3 12 4 3 7 21 8 17 10 2
3 12 4 3 7 8 21 17 10 2
3 12 4 3 7 8 17 21 10 2
3 12 4 3 7 8 17 10 21 2
3 12 4 3 7 8 17 10 2 21
Pass: 1
3 12 4 3 7 8 17 10 2 21
3 4 12 3 7 8 17 10 2 21
3 4 3 12 7 8 17 10 2 21
3 4 3 7 12 8 17 10 2 21
3 4 3 7 8 12 17 10 2 21
3 4 3 7 8 12 10 17 2 21
3 4 3 7 8 12 10 2 17 21
Pass: 2
3 4 3 7 8 12 10 2 17 21
3 3 4 7 8 12 10 2 17 21
3 3 4 7 8 10 12 2 17 21
3 3 4 7 8 10 2 12 17 21
Pass: 3
3 3 4 7 8 10 2 12 17 21
3 3 4 7 8 2 10 12 17 21
Pass: 4
3 3 4 7 8 2 10 12 17 21
3 3 4 7 2 8 10 12 17 21
Pass: 5
3 3 4 7 2 8 10 12 17 21
3 3 4 2 7 8 10 12 17 21
Pass: 6
3 3 4 2 7 8 10 12 17 21
3 3 2 4 7 8 10 12 17 21
Pass: 7
3 3 2 4 7 8 10 12 17 21
3 2 3 4 7 8 10 12 17 21
Pass: 8
3 2 3 4 7 8 10 12 17 21
2 3 3 4 7 8 10 12 17 21
Pass: 9
2 3 3 4 7 8 10 12 17 21
$a = [21, 3, 12, 4, 3, 7, 8, 17, 10, 2, ]
$c = [2, 3, 3, 4, 7, 8, 10, 12, 17, 21, ]

Quick Sort

Test

Sorting:$array = [23, 43, 54, 34, 25, 75, 1, 4, 98, 35, 21, 52, 87, 98765, ]
chose pivot:75
$less = [23, 43, 54, 34, 25, 1, 4, 35, 21, 52, ]
$equ = [75, ]
$greater = [98, 87, 98765, ]

   Sorting:   $array = [23, 43, 54, 34, 25, 1, 4, 35, 21, 52, ]
   chose pivot:43
   $less = [23, 34, 25, 1, 4, 35, 21, ]
   $equ = [43, ]
   $greater = [54, 52, ]

      Sorting:      $array = [23, 34, 25, 1, 4, 35, 21, ]
      chose pivot:1
      $less = []
      $equ = [1, ]
      $greater = [23, 34, 25, 4, 35, 21, ]

         $res = []

         Sorting:         $array = [23, 34, 25, 4, 35, 21, ]
         chose pivot:35
         $less = [23, 34, 25, 4, 21, ]
         $equ = [35, ]
         $greater = []

            Sorting:            $array = [23, 34, 25, 4, 21, ]
            chose pivot:25
            $less = [23, 4, 21, ]
            $equ = [25, ]
            $greater = [34, ]

               Sorting:               $array = [23, 4, 21, ]
               chose pivot:4
               $less = []
               $equ = [4, ]
               $greater = [23, 21, ]

                  $res = []

                  Sorting:                  $array = [23, 21, ]
                  chose pivot:21
                  $less = []
                  $equ = [21, ]
                  $greater = [23, ]

                     $res = []
                     $res = [23, ]
                  $res = [21, 23, ]
               $res = [4, 21, 23, ]
               $res = [34, ]
            $res = [4, 21, 23, 25, 34, ]
            $res = []
         $res = [4, 21, 23, 25, 34, 35, ]
      $res = [1, 4, 21, 23, 25, 34, 35, ]

      Sorting:      $array = [54, 52, ]
      chose pivot:54
      $less = [52, ]
      $equ = [54, ]
      $greater = []

         $res = [52, ]
         $res = []
      $res = [52, 54, ]
   $res = [1, 4, 21, 23, 25, 34, 35, 43, 52, 54, ]

   Sorting:   $array = [98, 87, 98765, ]
   chose pivot:98
   $less = [87, ]
   $equ = [98, ]
   $greater = [98765, ]

      $res = [87, ]
      $res = [98765, ]
   $res = [87, 98, 98765, ]
$res = [1, 4, 21, 23, 25, 34, 35, 43, 52, 54, 75, 87, 98, 98765, ]

Array =Array ( [0] => 23 [1] => 43 [2] => 54 [3] => 34 [4] => 25 [5] => 75 [6] => 1 [7] => 4 [8] => 98 [9] => 35 [10] => 21 [11] => 52 [12] => 87 [13] => 98765 )
Sorted =Array ( [0] => 1 [1] => 4 [2] => 21 [3] => 23 [4] => 25 [5] => 34 [6] => 35 [7] => 43 [8] => 52 [9] => 54 [10] => 75 [11] => 87 [12] => 98 [13] => 98765 )