3v4l.org

run code in 200+ PHP versions simultaneously
<?php function partition(&$arr, $left, $right) { $pivot = $arr[($left + $right)/2]; while ($left <= $right) { while ($arr[$left] < $pivot) $left++; while ($arr[$right] > $pivot) $right--; if ($left <= $right) { $tmp = $arr[$left]; $arr[$left] = $arr[$right]; $arr[$right] = $tmp; $left++; $right--; } } return $left; } function quickSort($arr, $left = 0, $right = null) { if(!$right) $right = (count($arr)-1); $index = partition($arr, $left, $right); if ($left < $index - 1) { $arr = quickSort($arr, $left, $index - 1); } if ($index < $right) { $arr = quickSort($arr, $index, $right); } return $arr; } $sortMe = [8,11,10,13,4,12,56,9]; print_r(quickSort($sortMe));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Vm4rd
function name:  (null)
number of ops:  8
compiled vars:  !0 = $sortMe
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  40     0  E >   QM_ASSIGN                                                !0
  41     1        INIT_FCALL                                               'print_r'
         2        INIT_FCALL                                               'quicksort'
         3        SEND_VAR                                                 !0
         4        DO_FCALL                                      0  $2      
         5        SEND_VAR                                                 $2
         6        DO_ICALL                                                 
         7      > RETURN                                                   1

Function partition:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
2 jumps found. (Code = 44) Position 1 = 35, Position 2 = 8
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 9
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
2 jumps found. (Code = 44) Position 1 = 20, Position 2 = 15
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 33
Branch analysis from position: 22
2 jumps found. (Code = 44) Position 1 = 35, Position 2 = 8
Branch analysis from position: 35
Branch analysis from position: 8
Branch analysis from position: 33
Branch analysis from position: 15
2 jumps found. (Code = 44) Position 1 = 20, Position 2 = 15
Branch analysis from position: 20
Branch analysis from position: 15
Branch analysis from position: 9
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 9
Branch analysis from position: 14
Branch analysis from position: 9
filename:       /in/Vm4rd
function name:  partition
number of ops:  37
compiled vars:  !0 = $arr, !1 = $left, !2 = $right, !3 = $pivot, !4 = $tmp
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   3     0  E >   RECV                                             !0      
         1        RECV                                             !1      
         2        RECV                                             !2      
   5     3        ADD                                              ~5      !1, !2
         4        DIV                                              ~6      ~5, 2
         5        FETCH_DIM_R                                      ~7      !0, ~6
         6        QM_ASSIGN                                                !3
   7     7      > JMP                                                      ->33
   9     8    > > JMP                                                      ->11
  10     9    >   POST_INC                                         ~9      !1
        10        FREE                                                     ~9
   9    11    >   FETCH_DIM_R                                      ~10     !0, !1
        12        IS_SMALLER_OR_EQUAL                              ~11     ~10, !3
        13      > JMPNZ                                                    ~11, ->9
  11    14    > > JMP                                                      ->17
  12    15    >   POST_DEC                                         ~12     !2
        16        FREE                                                     ~12
  11    17    >   FETCH_DIM_R                                      ~13     !0, !2
        18        IS_SMALLER_OR_EQUAL                              ~14     !3, ~13
        19      > JMPNZ                                                    ~14, ->15
  13    20    >   CAST                                          0  ~15     !1, !2
        21      > JMPZ                                                     ~15, ->33
  14    22    >   FETCH_DIM_R                                      ~16     !0, !1
        23        QM_ASSIGN                                                !4
  15    24        FETCH_DIM_R                                      ~19     !0, !2
        25        ASSIGN_ADD                                    0          !0, !1
        26        OP_DATA                                                  ~19
  16    27        ASSIGN_ADD                                    0          !0, !2
        28        OP_DATA                                                  !4
  17    29        POST_INC                                         ~21     !1
        30        FREE                                                     ~21
  18    31        POST_DEC                                         ~22     !2
        32        FREE                                                     ~22
   7    33    >   CAST                                          0  ~23     !1, !2
        34      > JMPNZ                                                    ~23, ->8
  22    35    > > RETURN                                                   !1
  23    36*     > RETURN                                                   null

End of function partition

Function quicksort:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 8
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 24
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 32
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 32
Branch analysis from position: 24
Branch analysis from position: 8
filename:       /in/Vm4rd
function name:  quickSort
number of ops:  34
compiled vars:  !0 = $arr, !1 = $left, !2 = $right, !3 = $index
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  25     0  E >   RECV                                             !0      
         1        RECV_INIT                                        !1      0
         2        RECV_INIT                                        !2      null
  27     3        BOOL_XOR                                         ~4      !2
         4      > JMPZ                                                     ~4, ->8
         5    >   COUNT                                            ~5      !0
         6        SUB                                              ~6      ~5, 1
         7        QM_ASSIGN                                                !2
  29     8    >   INIT_FCALL                                               'partition'
         9        SEND_REF                                                 !0
        10        SEND_VAR                                                 !1
        11        SEND_VAR                                                 !2
        12        DO_FCALL                                      0  $8      
        13        QM_ASSIGN                                                !3
  30    14        SUB                                              ~10     !3, 1
        15        IS_SMALLER_OR_EQUAL                              ~11     !1, ~10
        16      > JMPZ                                                     ~11, ->24
  31    17    >   INIT_FCALL_BY_NAME                                       'quickSort'
        18        SEND_VAR_EX                                              !0
        19        SEND_VAR_EX                                              !1
        20        SUB                                              ~12     !3, 1
        21        SEND_VAL_EX                                              ~12
        22        DO_FCALL                                      0  $13     
        23        QM_ASSIGN                                                !0
  33    24    >   IS_SMALLER_OR_EQUAL                              ~15     !3, !2
        25      > JMPZ                                                     ~15, ->32
  34    26    >   INIT_FCALL_BY_NAME                                       'quickSort'
        27        SEND_VAR_EX                                              !0
        28        SEND_VAR_EX                                              !3
        29        SEND_VAR_EX                                              !2
        30        DO_FCALL                                      0  $16     
        31        QM_ASSIGN                                                !0
  37    32    > > RETURN                                                   !0
  38    33*     > RETURN                                                   null

End of function quicksort

Generated using Vulcan Logic Dumper, using php 7.4.0