3v4l.org

run code in 300+ PHP versions simultaneously
<?php function mergeSort($array) { echo "array = " . json_encode($array) . "\n"; $count = count($array); if ($count == 1) { return $array; } $middle = $count / 2; // round/floor/ceil is unnecessary return merge( mergeSort(array_slice($array, 0, $middle)), mergeSort(array_slice($array, $middle)) ); } function merge($half1, $half2) { do { $temp[] = $half1[0] < $half2[0] ? array_shift($half1) : array_shift($half2); } while(isset($half1[0], $half2[0])); return array_merge($temp, $half1, $half2); } $input = [4, 2, 7, 5, 3]; $input = mergeSort($input); var_export($input);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/REQAa
function name:  (null)
number of ops:  9
compiled vars:  !0 = $input
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   ASSIGN                                                   !0, <array>
   24     1        INIT_FCALL                                               'mergesort'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $2      
          4        ASSIGN                                                   !0, $2
   25     5        INIT_FCALL                                               'var_export'
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                                 
          8      > RETURN                                                   1

Function mergesort:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 12
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/REQAa
function name:  mergeSort
number of ops:  35
compiled vars:  !0 = $array, !1 = $count, !2 = $middle
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        INIT_FCALL                                               'json_encode'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $3      
          4        CONCAT                                           ~4      'array+%3D+', $3
          5        CONCAT                                           ~5      ~4, '%0A'
          6        ECHO                                                     ~5
    5     7        COUNT                                            ~6      !0
          8        ASSIGN                                                   !1, ~6
    6     9        IS_EQUAL                                                 !1, 1
         10      > JMPZ                                                     ~8, ->12
    7    11    > > RETURN                                                   !0
    9    12    >   DIV                                              ~9      !1, 2
         13        ASSIGN                                                   !2, ~9
   10    14        INIT_FCALL_BY_NAME                                       'merge'
   11    15        INIT_FCALL_BY_NAME                                       'mergeSort'
         16        INIT_FCALL                                               'array_slice'
         17        SEND_VAR                                                 !0
         18        SEND_VAL                                                 0
         19        SEND_VAR                                                 !2
         20        DO_ICALL                                         $11     
         21        SEND_VAR_NO_REF_EX                                       $11
         22        DO_FCALL                                      0  $12     
         23        SEND_VAR_NO_REF_EX                                       $12
   12    24        INIT_FCALL_BY_NAME                                       'mergeSort'
         25        INIT_FCALL                                               'array_slice'
         26        SEND_VAR                                                 !0
         27        SEND_VAR                                                 !2
         28        DO_ICALL                                         $13     
         29        SEND_VAR_NO_REF_EX                                       $13
         30        DO_FCALL                                      0  $14     
         31        SEND_VAR_NO_REF_EX                                       $14
   10    32        DO_FCALL                                      0  $15     
   12    33      > RETURN                                                   $15
   14    34*     > RETURN                                                   null

End of function mergesort

Function merge:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 11
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
2 jumps found. (Code = 46) Position 1 = 19, Position 2 = 21
Branch analysis from position: 19
2 jumps found. (Code = 44) Position 1 = 22, Position 2 = 2
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 2
Branch analysis from position: 21
Branch analysis from position: 11
2 jumps found. (Code = 46) Position 1 = 19, Position 2 = 21
Branch analysis from position: 19
Branch analysis from position: 21
filename:       /in/REQAa
function name:  merge
number of ops:  29
compiled vars:  !0 = $half1, !1 = $half2, !2 = $temp
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   18     2    >   FETCH_DIM_R                                      ~4      !0, 0
          3        FETCH_DIM_R                                      ~5      !1, 0
          4        IS_SMALLER                                               ~4, ~5
          5      > JMPZ                                                     ~6, ->11
          6    >   INIT_FCALL                                               'array_shift'
          7        SEND_REF                                                 !0
          8        DO_ICALL                                         $7      
          9        QM_ASSIGN                                        ~8      $7
         10      > JMP                                                      ->15
         11    >   INIT_FCALL                                               'array_shift'
         12        SEND_REF                                                 !1
         13        DO_ICALL                                         $9      
         14        QM_ASSIGN                                        ~8      $9
         15    >   ASSIGN_DIM                                               !2
         16        OP_DATA                                                  ~8
   19    17        ISSET_ISEMPTY_DIM_OBJ                         0  ~10     !0, 0
         18      > JMPZ_EX                                          ~10     ~10, ->21
         19    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~11     !1, 0
         20        BOOL                                             ~10     ~11
         21    > > JMPNZ                                                    ~10, ->2
   20    22    >   INIT_FCALL                                               'array_merge'
         23        SEND_VAR                                                 !2
         24        SEND_VAR                                                 !0
         25        SEND_VAR                                                 !1
         26        DO_ICALL                                         $12     
         27      > RETURN                                                   $12
   21    28*     > RETURN                                                   null

End of function merge

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.39 ms | 1017 KiB | 19 Q