3v4l.org

run code in 300+ PHP versions simultaneously
<?php function mergeArray(array $arr1, array $arr2) { $keysStats = array(); foreach ($arr1 as $index => $key) { $keysStats[$key] = array( 'arr1' => $index, 'arr2' => null ); } foreach ($arr2 as $index => $key) { if (!is_array($keysStats[$key])) { $keysStats[$key] = array( 'arr1' => null, 'arr2' => $index ); } else { $keysStats[$key]['arr2'] = $index; } } $allKeys = array_keys($keysStats); sort($allKeys); $merged = array(); foreach ($allKeys as $key) { if (is_null($keysStats[$key]['arr2'])) { $merged[] = null; } else { $merged[] = $arr2[$keysStats[$key]['arr2']]; } } return $arrMerged; } print_r(mergeArray( array( 'a', 'b', 'c', 'd', 'e', 'f', 'g' ), array( 'a', 'b', 'z', 'q' ) ));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WuDnX
function name:  (null)
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   INIT_FCALL                                               'print_r'
          1        INIT_FCALL                                               'mergearray'
   41     2        SEND_VAL                                                 <array>
   44     3        SEND_VAL                                                 <array>
          4        DO_FCALL                                      0  $0      
          5        SEND_VAR                                                 $0
          6        DO_ICALL                                                 
   46     7      > RETURN                                                   1

Function mergearray:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 11
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 11
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 11
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 28
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 28
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 24
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 28
2 jumps found. (Code = 77) Position 1 = 38, Position 2 = 52
Branch analysis from position: 38
2 jumps found. (Code = 78) Position 1 = 39, Position 2 = 52
Branch analysis from position: 39
2 jumps found. (Code = 43) Position 1 = 43, Position 2 = 46
Branch analysis from position: 43
1 jumps found. (Code = 42) Position 1 = 51
Branch analysis from position: 51
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
Branch analysis from position: 46
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
Branch analysis from position: 52
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 52
Branch analysis from position: 28
Branch analysis from position: 11
filename:       /in/WuDnX
function name:  mergeArray
number of ops:  55
compiled vars:  !0 = $arr1, !1 = $arr2, !2 = $keysStats, !3 = $key, !4 = $index, !5 = $allKeys, !6 = $merged, !7 = $arrMerged
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    3     2        ASSIGN                                                   !2, <array>
    5     3      > FE_RESET_R                                       $9      !0, ->11
          4    > > FE_FETCH_R                                       ~10     $9, !3, ->11
          5    >   ASSIGN                                                   !4, ~10
    7     6        INIT_ARRAY                                       ~13     !4, 'arr1'
          7        ADD_ARRAY_ELEMENT                                ~13     null, 'arr2'
    6     8        ASSIGN_DIM                                               !2, !3
    7     9        OP_DATA                                                  ~13
    5    10      > JMP                                                      ->4
         11    >   FE_FREE                                                  $9
   12    12      > FE_RESET_R                                       $14     !1, ->28
         13    > > FE_FETCH_R                                       ~15     $14, !3, ->28
         14    >   ASSIGN                                                   !4, ~15
   13    15        FETCH_DIM_R                                      ~17     !2, !3
         16        TYPE_CHECK                                  128  ~18     ~17
         17        BOOL_NOT                                         ~19     ~18
         18      > JMPZ                                                     ~19, ->24
   15    19    >   INIT_ARRAY                                       ~21     null, 'arr1'
   16    20        ADD_ARRAY_ELEMENT                                ~21     !4, 'arr2'
   14    21        ASSIGN_DIM                                               !2, !3
   16    22        OP_DATA                                                  ~21
         23      > JMP                                                      ->27
   19    24    >   FETCH_DIM_W                                      $22     !2, !3
         25        ASSIGN_DIM                                               $22, 'arr2'
         26        OP_DATA                                                  !4
   12    27    > > JMP                                                      ->13
         28    >   FE_FREE                                                  $14
   23    29        INIT_FCALL                                               'array_keys'
         30        SEND_VAR                                                 !2
         31        DO_ICALL                                         $24     
         32        ASSIGN                                                   !5, $24
   24    33        INIT_FCALL                                               'sort'
         34        SEND_REF                                                 !5
         35        DO_ICALL                                                 
   26    36        ASSIGN                                                   !6, <array>
   28    37      > FE_RESET_R                                       $28     !5, ->52
         38    > > FE_FETCH_R                                               $28, !3, ->52
   29    39    >   FETCH_DIM_R                                      ~29     !2, !3
         40        FETCH_DIM_R                                      ~30     ~29, 'arr2'
         41        TYPE_CHECK                                    2          ~30
         42      > JMPZ                                                     ~31, ->46
   30    43    >   ASSIGN_DIM                                               !6
         44        OP_DATA                                                  null
         45      > JMP                                                      ->51
   32    46    >   FETCH_DIM_R                                      ~34     !2, !3
         47        FETCH_DIM_R                                      ~35     ~34, 'arr2'
         48        FETCH_DIM_R                                      ~36     !1, ~35
         49        ASSIGN_DIM                                               !6
         50        OP_DATA                                                  ~36
   28    51    > > JMP                                                      ->38
         52    >   FE_FREE                                                  $28
   36    53      > RETURN                                                   !7
   37    54*     > RETURN                                                   null

End of function mergearray

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.73 ms | 1394 KiB | 20 Q