3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* * make sure the setA and setB are the same */ function isSame($setA, $setB) { var_dump($setA); var_dump($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($setA)) || (count($keys) != count($setB))) { return false; } foreach ($keys as $key) { if (!isSame($setA[$key], $setB[$key])) { 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); foreach ($setB as $k=>$v) { if (array_key_exists($k, $setA)) { if (!isSame($setA[$k], $v)) { return false; } } else { return false; } } return true; } $a=array(101=>array(1,2,3)); $b=array(101=>array(1,2,3)); echo hasAllCapabilities($a, $b);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/smoAc
function name:  (null)
number of ops:  8
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   65     0  E >   ASSIGN                                                   !0, <array>
   66     1        ASSIGN                                                   !1, <array>
   67     2        INIT_FCALL                                               'hasallcapabilities'
          3        SEND_VAR                                                 !0
          4        SEND_VAR                                                 !1
          5        DO_FCALL                                      0  $4      
          6        ECHO                                                     $4
          7      > RETURN                                                   1

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

End of function issame

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
2 jumps found. (Code = 77) Position 1 = 21, Position 2 = 38
Branch analysis from position: 21
2 jumps found. (Code = 78) Position 1 = 22, Position 2 = 38
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 35
Branch analysis from position: 25
2 jumps found. (Code = 43) Position 1 = 32, Position 2 = 34
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 38
Branch analysis from position: 20
Branch analysis from position: 15
Branch analysis from position: 11
Branch analysis from position: 6
filename:       /in/smoAc
function name:  hasAllCapabilities
number of ops:  41
compiled vars:  !0 = $setA, !1 = $setB, !2 = $v, !3 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   40     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   42     2        ISSET_ISEMPTY_CV                                 ~4      !0
          3        BOOL_NOT                                         ~5      ~4
          4      > JMPZ                                                     ~5, ->6
   43     5    >   ASSIGN                                                   !0, <array>
   44     6    >   TYPE_CHECK                                  128  ~7      !0
          7        BOOL_NOT                                         ~8      ~7
          8      > JMPZ                                                     ~8, ->11
   45     9    >   INIT_ARRAY                                       ~9      !0
         10        ASSIGN                                                   !0, ~9
   47    11    >   ISSET_ISEMPTY_CV                                 ~11     !1
         12        BOOL_NOT                                         ~12     ~11
         13      > JMPZ                                                     ~12, ->15
   48    14    >   ASSIGN                                                   !1, <array>
   49    15    >   TYPE_CHECK                                  128  ~14     !1
         16        BOOL_NOT                                         ~15     ~14
         17      > JMPZ                                                     ~15, ->20
   50    18    >   INIT_ARRAY                                       ~16     !1
         19        ASSIGN                                                   !1, ~16
   52    20    > > FE_RESET_R                                       $18     !1, ->38
         21    > > FE_FETCH_R                                       ~19     $18, !2, ->38
         22    >   ASSIGN                                                   !3, ~19
   53    23        ARRAY_KEY_EXISTS                                         !3, !0
         24      > JMPZ                                                     ~21, ->35
   54    25    >   INIT_FCALL                                               'issame'
         26        FETCH_DIM_R                                      ~22     !0, !3
         27        SEND_VAL                                                 ~22
         28        SEND_VAR                                                 !2
         29        DO_FCALL                                      0  $23     
         30        BOOL_NOT                                         ~24     $23
         31      > JMPZ                                                     ~24, ->34
   55    32    >   FE_FREE                                                  $18
         33      > RETURN                                                   <false>
         34    > > JMP                                                      ->37
   58    35    >   FE_FREE                                                  $18
         36      > RETURN                                                   <false>
   52    37    > > JMP                                                      ->21
         38    >   FE_FREE                                                  $18
   61    39      > RETURN                                                   <true>
   63    40*     > RETURN                                                   null

End of function hasallcapabilities

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.11 ms | 1411 KiB | 19 Q