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($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 $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/ulZSM
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 = 30
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 30
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 26
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 30
2 jumps found. (Code = 77) Position 1 = 40, Position 2 = 54
Branch analysis from position: 40
2 jumps found. (Code = 78) Position 1 = 41, Position 2 = 54
Branch analysis from position: 41
2 jumps found. (Code = 43) Position 1 = 45, Position 2 = 48
Branch analysis from position: 45
1 jumps found. (Code = 42) Position 1 = 53
Branch analysis from position: 53
1 jumps found. (Code = 42) Position 1 = 40
Branch analysis from position: 40
Branch analysis from position: 48
1 jumps found. (Code = 42) Position 1 = 40
Branch analysis from position: 40
Branch analysis from position: 54
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 54
Branch analysis from position: 30
Branch analysis from position: 11
filename:       /in/ulZSM
function name:  mergeArray
number of ops:  57
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, ->30
         13    > > FE_FETCH_R                                       ~14     $13, !3, ->30
         14    >   ASSIGN                                                   !4, ~14
   13    15        INIT_FCALL                                               'array_key_exists'
         16        FETCH_DIM_R                                      ~16     !2, !3
         17        SEND_VAL                                                 ~16
         18        DO_ICALL                                         $17     
         19        BOOL_NOT                                         ~18     $17
         20      > JMPZ                                                     ~18, ->26
   15    21    >   INIT_ARRAY                                       ~20     null, 'arr1'
   16    22        ADD_ARRAY_ELEMENT                                ~20     !4, 'arr2'
   14    23        ASSIGN_DIM                                               !2, !3
   16    24        OP_DATA                                                  ~20
         25      > JMP                                                      ->29
   19    26    >   FETCH_DIM_W                                      $21     !2, !3
         27        ASSIGN_DIM                                               $21, 'arr2'
         28        OP_DATA                                                  !4
   12    29    > > JMP                                                      ->13
         30    >   FE_FREE                                                  $13
   23    31        INIT_FCALL                                               'array_keys'
         32        SEND_VAR                                                 !2
         33        DO_ICALL                                         $23     
         34        ASSIGN                                                   !5, $23
   24    35        INIT_FCALL                                               'sort'
         36        SEND_REF                                                 !5
         37        DO_ICALL                                                 
   26    38        ASSIGN                                                   !6, <array>
   28    39      > FE_RESET_R                                       $27     !5, ->54
         40    > > FE_FETCH_R                                               $27, !3, ->54
   29    41    >   FETCH_DIM_R                                      ~28     !2, !3
         42        FETCH_DIM_R                                      ~29     ~28, 'arr2'
         43        TYPE_CHECK                                    2          ~29
         44      > JMPZ                                                     ~30, ->48
   30    45    >   ASSIGN_DIM                                               !6
         46        OP_DATA                                                  null
         47      > JMP                                                      ->53
   32    48    >   FETCH_DIM_R                                      ~33     !2, !3
         49        FETCH_DIM_R                                      ~34     ~33, 'arr2'
         50        FETCH_DIM_R                                      ~35     !1, ~34
         51        ASSIGN_DIM                                               !6
         52        OP_DATA                                                  ~35
   28    53    > > JMP                                                      ->40
         54    >   FE_FREE                                                  $27
   36    55      > RETURN                                                   !6
   37    56*     > RETURN                                                   null

End of function mergearray

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
167.56 ms | 1403 KiB | 22 Q