3v4l.org

run code in 300+ PHP versions simultaneously
<?php $haystack = [7, 6, 14, 15, 8, 0, 1, 4, 5, 9]; $needles = [ [3, 2, 7, 6], [7, 6, 15, 14], [15,14,11,10], [1,3,5,7], [5,7,13,15], [13,15,9,11], [0,1,4,5], [4,5,12,13], ]; // assuming all needle values are unique and all values in each haystacks subarray are unique function getIndexOfMatchingArrays(array $needles, array $haystack) { if (!$haystack) { return -1; } foreach ($needles as $index => $needle) { if ($needle === array_intersect($needle, $haystack)) { $fullMatch[] = $index; } } return $fullMatch ?? -1; } var_export( getIndexOfMatchingArrays($needles, $haystack) );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0aHB4
function name:  (null)
number of ops:  10
compiled vars:  !0 = $haystack, !1 = $needles
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    4     1        ASSIGN                                                   !1, <array>
   28     2        INIT_FCALL                                               'var_export'
   29     3        INIT_FCALL                                               'getindexofmatchingarrays'
          4        SEND_VAR                                                 !1
          5        SEND_VAR                                                 !0
          6        DO_FCALL                                      0  $4      
          7        SEND_VAR                                                 $4
          8        DO_ICALL                                                 
   30     9      > RETURN                                                   1

Function getindexofmatchingarrays:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 5
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 17
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 17
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 16
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 16
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
filename:       /in/0aHB4
function name:  getIndexOfMatchingArrays
number of ops:  22
compiled vars:  !0 = $needles, !1 = $haystack, !2 = $needle, !3 = $index, !4 = $fullMatch
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   17     2        BOOL_NOT                                         ~5      !1
          3      > JMPZ                                                     ~5, ->5
   18     4    > > RETURN                                                   -1
   20     5    > > FE_RESET_R                                       $6      !0, ->17
          6    > > FE_FETCH_R                                       ~7      $6, !2, ->17
          7    >   ASSIGN                                                   !3, ~7
   21     8        INIT_FCALL                                               'array_intersect'
          9        SEND_VAR                                                 !2
         10        SEND_VAR                                                 !1
         11        DO_ICALL                                         $9      
         12        IS_IDENTICAL                                             !2, $9
         13      > JMPZ                                                     ~10, ->16
   22    14    >   ASSIGN_DIM                                               !4
         15        OP_DATA                                                  !3
   20    16    > > JMP                                                      ->6
         17    >   FE_FREE                                                  $6
   25    18        COALESCE                                         ~12     !4
         19        QM_ASSIGN                                        ~12     -1
         20      > RETURN                                                   ~12
   26    21*     > RETURN                                                   null

End of function getindexofmatchingarrays

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
146.39 ms | 1407 KiB | 18 Q