3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* * make sure the setA is super set of setB */ function isSuperSet($setA, $setB) { if (!is_array($setA) && !is_array($setB)) { return $setA == $setB; } if (!is_array($setA) || !is_array($setB)) { return false; } $keys = array_intersect_key($setA, $setB); if (count($keys) != count($setB)) { return false; } foreach ($keys as $k => $v) { if (!isSuperSet($setA[$k], $setB[$k])) { return false; } } return true; } /* * return true if setA has all capabilities in setB. Here the comparison is on actual capabilities, and nothing * fancy like number of capabilities or a weighted sum of capabilities. In other words, return true if setB is a * subset of setA. * * NOTE: This function does not validate if the inputs are really capability lists. * * @param array setA - master list to compare against * @param array setB - subset to be compared * * @return bool */ function hasAllCapabilities($setA, $setB) { if(!isset($setA)) $setA = array(); if(!is_array($setA)) $setA = array($setA); if(!isset($setB)) $setB = array(); if(!is_array($setB)) $setB = array($setB); return isSuperSet($setA, $setB); } $a=array(101=>array(1,2,3), 100=>array(2,3)); $b=array(101=>array(1)); echo hasAllCapabilities($a, $b);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/deA6I
function name:  (null)
number of ops:  8
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   53     0  E >   ASSIGN                                                   !0, <array>
   54     1        ASSIGN                                                   !1, <array>
   55     2        INIT_FCALL                                               'hasallcapabilities'
          3        SEND_VAR                                                 !0
          4        SEND_VAR                                                 !1
          5        DO_FCALL                                      0  $4      
          6        ECHO                                                     $4
          7      > RETURN                                                   1

Function issuperset:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 5, Position 2 = 8
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 11
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
2 jumps found. (Code = 47) Position 1 = 14, Position 2 = 17
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 19
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 29
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
2 jumps found. (Code = 77) Position 1 = 30, Position 2 = 45
Branch analysis from position: 30
2 jumps found. (Code = 78) Position 1 = 31, Position 2 = 45
Branch analysis from position: 31
2 jumps found. (Code = 43) Position 1 = 42, Position 2 = 44
Branch analysis from position: 42
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 44
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
Branch analysis from position: 45
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 45
Branch analysis from position: 17
Branch analysis from position: 8
filename:       /in/deA6I
function name:  isSuperSet
number of ops:  48
compiled vars:  !0 = $setA, !1 = $setB, !2 = $keys, !3 = $v, !4 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    6     2        TYPE_CHECK                                  128  ~5      !0
          3        BOOL_NOT                                         ~6      ~5
          4      > JMPZ_EX                                          ~6      ~6, ->8
          5    >   TYPE_CHECK                                  128  ~7      !1
          6        BOOL_NOT                                         ~8      ~7
          7        BOOL                                             ~6      ~8
          8    > > JMPZ                                                     ~6, ->11
    7     9    >   IS_EQUAL                                         ~9      !0, !1
         10      > RETURN                                                   ~9
    9    11    >   TYPE_CHECK                                  128  ~10     !0
         12        BOOL_NOT                                         ~11     ~10
         13      > JMPNZ_EX                                         ~11     ~11, ->17
         14    >   TYPE_CHECK                                  128  ~12     !1
         15        BOOL_NOT                                         ~13     ~12
         16        BOOL                                             ~11     ~13
         17    > > JMPZ                                                     ~11, ->19
   10    18    > > RETURN                                                   <false>
   13    19    >   INIT_FCALL                                               'array_intersect_key'
         20        SEND_VAR                                                 !0
         21        SEND_VAR                                                 !1
         22        DO_ICALL                                         $14     
         23        ASSIGN                                                   !2, $14
   14    24        COUNT                                            ~16     !2
         25        COUNT                                            ~17     !1
         26        IS_NOT_EQUAL                                             ~16, ~17
         27      > JMPZ                                                     ~18, ->29
   15    28    > > RETURN                                                   <false>
   18    29    > > FE_RESET_R                                       $19     !2, ->45
         30    > > FE_FETCH_R                                       ~20     $19, !3, ->45
         31    >   ASSIGN                                                   !4, ~20
   19    32        INIT_FCALL_BY_NAME                                       'isSuperSet'
         33        CHECK_FUNC_ARG                                           
         34        FETCH_DIM_FUNC_ARG                               $22     !0, !4
         35        SEND_FUNC_ARG                                            $22
         36        CHECK_FUNC_ARG                                           
         37        FETCH_DIM_FUNC_ARG                               $23     !1, !4
         38        SEND_FUNC_ARG                                            $23
         39        DO_FCALL                                      0  $24     
         40        BOOL_NOT                                         ~25     $24
         41      > JMPZ                                                     ~25, ->44
   20    42    >   FE_FREE                                                  $19
         43      > RETURN                                                   <false>
   18    44    > > JMP                                                      ->30
         45    >   FE_FREE                                                  $19
   23    46      > RETURN                                                   <true>
   24    47*     > RETURN                                                   null

End of function issuperset

Function hasallcapabilities:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 6
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 11
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 15
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 20
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
Branch analysis from position: 15
Branch analysis from position: 11
Branch analysis from position: 6
filename:       /in/deA6I
function name:  hasAllCapabilities
number of ops:  26
compiled vars:  !0 = $setA, !1 = $setB
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   39     2        ISSET_ISEMPTY_CV                                 ~2      !0
          3        BOOL_NOT                                         ~3      ~2
          4      > JMPZ                                                     ~3, ->6
   40     5    >   ASSIGN                                                   !0, <array>
   41     6    >   TYPE_CHECK                                  128  ~5      !0
          7        BOOL_NOT                                         ~6      ~5
          8      > JMPZ                                                     ~6, ->11
   42     9    >   INIT_ARRAY                                       ~7      !0
         10        ASSIGN                                                   !0, ~7
   44    11    >   ISSET_ISEMPTY_CV                                 ~9      !1
         12        BOOL_NOT                                         ~10     ~9
         13      > JMPZ                                                     ~10, ->15
   45    14    >   ASSIGN                                                   !1, <array>
   46    15    >   TYPE_CHECK                                  128  ~12     !1
         16        BOOL_NOT                                         ~13     ~12
         17      > JMPZ                                                     ~13, ->20
   47    18    >   INIT_ARRAY                                       ~14     !1
         19        ASSIGN                                                   !1, ~14
   49    20    >   INIT_FCALL                                               'issuperset'
         21        SEND_VAR                                                 !0
         22        SEND_VAR                                                 !1
         23        DO_FCALL                                      0  $16     
         24      > RETURN                                                   $16
   51    25*     > RETURN                                                   null

End of function hasallcapabilities

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
147.61 ms | 1407 KiB | 17 Q