3v4l.org

run code in 300+ PHP versions simultaneously
<?php $src = ["apple", "cherry", "grape", "lemon", "orange", "strawberry", "cherry", "cherry"]; $dst = ["apple", "banana", "cherry", "orange", "pear", "cherry"]; $result = []; while ($src && $dst) { if ($src[0] === $dst[0]) { // align identical values $result[] = [array_shift($src), array_shift($dst)]; continue; } $earliestSrcMatch = array_search($src[0], $dst); $earliestDstMatch = array_search($dst[0], $src); if ($earliestSrcMatch === $earliestDstMatch) { //both false (not 0) $result[] = [array_shift($src), null]; $result[] = [null, array_shift($dst)]; continue; } elseif ( $earliestDstMatch === false || ( $earliestSrcMatch !== false && $earliestSrcMatch < $earliestDstMatch ) ) { while ($dst && $src[0] !== $dst[0]) { $result[] = [null, array_shift($dst)]; } } elseif ( $earliestSrcMatch === false || $earliestSrcMatch > $earliestDstMatch ) { while ($src && $src[0] !== $dst[0]) { $result[] = [array_shift($src), null]; } } } while ($src) { $result[] = [array_shift($src), null]; } while ($dst) { $result[] = [null, array_shift($dst)]; } echo "<table border=1> "; foreach ($result as $i => [$s, $d]) { printf( "<tr> <td>%d</td> <td>%s</td> <td>%s</td> </tr>\n", ++$i, $s, $d ); } echo "</table>";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 91
Branch analysis from position: 91
2 jumps found. (Code = 46) Position 1 = 92, Position 2 = 93
Branch analysis from position: 92
2 jumps found. (Code = 44) Position 1 = 94, Position 2 = 4
Branch analysis from position: 94
1 jumps found. (Code = 42) Position 1 = 102
Branch analysis from position: 102
2 jumps found. (Code = 44) Position 1 = 103, Position 2 = 95
Branch analysis from position: 103
1 jumps found. (Code = 42) Position 1 = 111
Branch analysis from position: 111
2 jumps found. (Code = 44) Position 1 = 112, Position 2 = 104
Branch analysis from position: 112
2 jumps found. (Code = 77) Position 1 = 114, Position 2 = 129
Branch analysis from position: 114
2 jumps found. (Code = 78) Position 1 = 115, Position 2 = 129
Branch analysis from position: 115
1 jumps found. (Code = 42) Position 1 = 114
Branch analysis from position: 114
Branch analysis from position: 129
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 129
Branch analysis from position: 104
2 jumps found. (Code = 44) Position 1 = 112, Position 2 = 104
Branch analysis from position: 112
Branch analysis from position: 104
Branch analysis from position: 95
2 jumps found. (Code = 44) Position 1 = 103, Position 2 = 95
Branch analysis from position: 103
Branch analysis from position: 95
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 19
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 91
Branch analysis from position: 91
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 33, Position 2 = 49
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 91
Branch analysis from position: 91
Branch analysis from position: 49
2 jumps found. (Code = 47) Position 1 = 51, Position 2 = 56
Branch analysis from position: 51
2 jumps found. (Code = 46) Position 1 = 53, Position 2 = 55
Branch analysis from position: 53
2 jumps found. (Code = 43) Position 1 = 57, Position 2 = 72
Branch analysis from position: 57
1 jumps found. (Code = 42) Position 1 = 65
Branch analysis from position: 65
2 jumps found. (Code = 46) Position 1 = 66, Position 2 = 70
Branch analysis from position: 66
2 jumps found. (Code = 44) Position 1 = 71, Position 2 = 58
Branch analysis from position: 71
1 jumps found. (Code = 42) Position 1 = 91
Branch analysis from position: 91
Branch analysis from position: 58
2 jumps found. (Code = 46) Position 1 = 66, Position 2 = 70
Branch analysis from position: 66
Branch analysis from position: 70
Branch analysis from position: 70
Branch analysis from position: 72
2 jumps found. (Code = 47) Position 1 = 74, Position 2 = 76
Branch analysis from position: 74
2 jumps found. (Code = 43) Position 1 = 77, Position 2 = 91
Branch analysis from position: 77
1 jumps found. (Code = 42) Position 1 = 85
Branch analysis from position: 85
2 jumps found. (Code = 46) Position 1 = 86, Position 2 = 90
Branch analysis from position: 86
2 jumps found. (Code = 44) Position 1 = 91, Position 2 = 78
Branch analysis from position: 91
Branch analysis from position: 78
2 jumps found. (Code = 46) Position 1 = 86, Position 2 = 90
Branch analysis from position: 86
Branch analysis from position: 90
Branch analysis from position: 90
Branch analysis from position: 91
Branch analysis from position: 76
Branch analysis from position: 55
Branch analysis from position: 56
Branch analysis from position: 93
filename:       /in/KiYSi
function name:  (null)
number of ops:  132
compiled vars:  !0 = $src, !1 = $dst, !2 = $result, !3 = $earliestSrcMatch, !4 = $earliestDstMatch, !5 = $s, !6 = $d, !7 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   ASSIGN                                                   !0, <array>
    5     1        ASSIGN                                                   !1, <array>
    7     2        ASSIGN                                                   !2, <array>
    8     3      > JMP                                                      ->91
    9     4    >   FETCH_DIM_R                                      ~11     !0, 0
          5        FETCH_DIM_R                                      ~12     !1, 0
          6        IS_IDENTICAL                                             ~11, ~12
          7      > JMPZ                                                     ~13, ->19
   10     8    >   INIT_FCALL                                               'array_shift'
          9        SEND_REF                                                 !0
         10        DO_ICALL                                         $15     
         11        INIT_ARRAY                                       ~16     $15
         12        INIT_FCALL                                               'array_shift'
         13        SEND_REF                                                 !1
         14        DO_ICALL                                         $17     
         15        ADD_ARRAY_ELEMENT                                ~16     $17
         16        ASSIGN_DIM                                               !2
         17        OP_DATA                                                  ~16
   11    18      > JMP                                                      ->91
   14    19    >   INIT_FCALL                                               'array_search'
         20        FETCH_DIM_R                                      ~18     !0, 0
         21        SEND_VAL                                                 ~18
         22        SEND_VAR                                                 !1
         23        DO_ICALL                                         $19     
         24        ASSIGN                                                   !3, $19
   15    25        INIT_FCALL                                               'array_search'
         26        FETCH_DIM_R                                      ~21     !1, 0
         27        SEND_VAL                                                 ~21
         28        SEND_VAR                                                 !0
         29        DO_ICALL                                         $22     
         30        ASSIGN                                                   !4, $22
   17    31        IS_IDENTICAL                                             !3, !4
         32      > JMPZ                                                     ~24, ->49
   18    33    >   INIT_FCALL                                               'array_shift'
         34        SEND_REF                                                 !0
         35        DO_ICALL                                         $26     
         36        INIT_ARRAY                                       ~27     $26
         37        ADD_ARRAY_ELEMENT                                ~27     null
         38        ASSIGN_DIM                                               !2
         39        OP_DATA                                                  ~27
   19    40        INIT_ARRAY                                       ~29     null
         41        INIT_FCALL                                               'array_shift'
         42        SEND_REF                                                 !1
         43        DO_ICALL                                         $30     
         44        ADD_ARRAY_ELEMENT                                ~29     $30
         45        ASSIGN_DIM                                               !2
         46        OP_DATA                                                  ~29
   20    47      > JMP                                                      ->91
   17    48*       JMP                                                      ->91
   22    49    >   TYPE_CHECK                                    4  ~31     !4
         50      > JMPNZ_EX                                         ~31     ~31, ->56
   24    51    >   TYPE_CHECK                                  1018  ~32     !3
         52      > JMPZ_EX                                          ~32     ~32, ->55
   25    53    >   IS_SMALLER                                       ~33     !3, !4
         54        BOOL                                             ~32     ~33
         55    >   BOOL                                             ~31     ~32
         56    > > JMPZ                                                     ~31, ->72
   28    57    > > JMP                                                      ->65
   29    58    >   INIT_ARRAY                                       ~35     null
         59        INIT_FCALL                                               'array_shift'
         60        SEND_REF                                                 !1
         61        DO_ICALL                                         $36     
         62        ADD_ARRAY_ELEMENT                                ~35     $36
         63        ASSIGN_DIM                                               !2
         64        OP_DATA                                                  ~35
   28    65    > > JMPZ_EX                                          ~37     !1, ->70
         66    >   FETCH_DIM_R                                      ~38     !0, 0
         67        FETCH_DIM_R                                      ~39     !1, 0
         68        IS_NOT_IDENTICAL                                 ~40     ~38, ~39
         69        BOOL                                             ~37     ~40
         70    > > JMPNZ                                                    ~37, ->58
   22    71    > > JMP                                                      ->91
   32    72    >   TYPE_CHECK                                    4  ~41     !3
         73      > JMPNZ_EX                                         ~41     ~41, ->76
   33    74    >   IS_SMALLER                                       ~42     !4, !3
         75        BOOL                                             ~41     ~42
         76    > > JMPZ                                                     ~41, ->91
   35    77    > > JMP                                                      ->85
   36    78    >   INIT_FCALL                                               'array_shift'
         79        SEND_REF                                                 !0
         80        DO_ICALL                                         $44     
         81        INIT_ARRAY                                       ~45     $44
         82        ADD_ARRAY_ELEMENT                                ~45     null
         83        ASSIGN_DIM                                               !2
         84        OP_DATA                                                  ~45
   35    85    > > JMPZ_EX                                          ~46     !0, ->90
         86    >   FETCH_DIM_R                                      ~47     !0, 0
         87        FETCH_DIM_R                                      ~48     !1, 0
         88        IS_NOT_IDENTICAL                                 ~49     ~47, ~48
         89        BOOL                                             ~46     ~49
         90    > > JMPNZ                                                    ~46, ->78
    8    91    > > JMPZ_EX                                          ~50     !0, ->93
         92    >   BOOL                                             ~50     !1
         93    > > JMPNZ                                                    ~50, ->4
   40    94    > > JMP                                                      ->102
   41    95    >   INIT_FCALL                                               'array_shift'
         96        SEND_REF                                                 !0
         97        DO_ICALL                                         $52     
         98        INIT_ARRAY                                       ~53     $52
         99        ADD_ARRAY_ELEMENT                                ~53     null
        100        ASSIGN_DIM                                               !2
        101        OP_DATA                                                  ~53
   40   102    > > JMPNZ                                                    !0, ->95
   43   103    > > JMP                                                      ->111
   44   104    >   INIT_ARRAY                                       ~55     null
        105        INIT_FCALL                                               'array_shift'
        106        SEND_REF                                                 !1
        107        DO_ICALL                                         $56     
        108        ADD_ARRAY_ELEMENT                                ~55     $56
        109        ASSIGN_DIM                                               !2
        110        OP_DATA                                                  ~55
   43   111    > > JMPNZ                                                    !1, ->104
   47   112    >   ECHO                                                     '%3Ctable+border%3D1%3E%0A'
   49   113      > FE_RESET_R                                       $57     !2, ->129
        114    > > FE_FETCH_R                                       ~63     $57, $58, ->129
        115    >   FETCH_LIST_R                                     $59     $58, 0
        116        ASSIGN                                                   !5, $59
        117        FETCH_LIST_R                                     $61     $58, 1
        118        ASSIGN                                                   !6, $61
        119        FREE                                                     $58
        120        ASSIGN                                                   !7, ~63
   50   121        INIT_FCALL                                               'printf'
   51   122        SEND_VAL                                                 '%3Ctr%3E%0A+++++++++++++%3Ctd%3E%25d%3C%2Ftd%3E%0A+++++++++++++%3Ctd%3E%25s%3C%2Ftd%3E%0A+++++++++++++%3Ctd%3E%25s%3C%2Ftd%3E%0A+++++++++%3C%2Ftr%3E%0A'
   56   123        PRE_INC                                          ~65     !7
        124        SEND_VAL                                                 ~65
   57   125        SEND_VAR                                                 !5
   58   126        SEND_VAR                                                 !6
   50   127        DO_ICALL                                                 
   49   128      > JMP                                                      ->114
        129    >   FE_FREE                                                  $57
   61   130        ECHO                                                     '%3C%2Ftable%3E'
        131      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
166.99 ms | 1096 KiB | 16 Q