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

End of function mergearray

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.88 ms | 1394 KiB | 18 Q