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

End of function mergearray

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.85 ms | 1394 KiB | 18 Q