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

End of function mergearray

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.63 ms | 1394 KiB | 20 Q