3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* * make sure the setA and setB are the same */ function isSame($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($setA)) || (count($keys) != count($setB))) { return false; } foreach ($keys as $k => $v) { if (!isSame($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); 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), 100=>array(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/s5l6e
function name:  (null)
number of ops:  8
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   64     0  E >   ASSIGN                                                   !0, <array>
   65     1        ASSIGN                                                   !1, <array>
   66     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 = 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 = 47) Position 1 = 28, Position 2 = 32
Branch analysis from position: 28
2 jumps found. (Code = 43) Position 1 = 33, Position 2 = 34
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
2 jumps found. (Code = 77) Position 1 = 35, Position 2 = 50
Branch analysis from position: 35
2 jumps found. (Code = 78) Position 1 = 36, Position 2 = 50
Branch analysis from position: 36
2 jumps found. (Code = 43) Position 1 = 47, Position 2 = 49
Branch analysis from position: 47
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 49
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
Branch analysis from position: 50
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 50
Branch analysis from position: 32
Branch analysis from position: 17
Branch analysis from position: 8
filename:       /in/s5l6e
function name:  isSame
number of ops:  53
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      
    8     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
    9     9    >   IS_EQUAL                                         ~9      !0, !1
         10      > RETURN                                                   ~9
   11    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
   12    18    > > RETURN                                                   <false>
   15    19    >   INIT_FCALL                                               'array_intersect_key'
         20        SEND_VAR                                                 !0
         21        SEND_VAR                                                 !1
         22        DO_ICALL                                         $14     
         23        ASSIGN                                                   !2, $14
   16    24        COUNT                                            ~16     !2
         25        COUNT                                            ~17     !0
         26        IS_NOT_EQUAL                                     ~18     ~16, ~17
         27      > JMPNZ_EX                                         ~18     ~18, ->32
         28    >   COUNT                                            ~19     !2
         29        COUNT                                            ~20     !1
         30        IS_NOT_EQUAL                                     ~21     ~19, ~20
         31        BOOL                                             ~18     ~21
         32    > > JMPZ                                                     ~18, ->34
   17    33    > > RETURN                                                   <false>
   20    34    > > FE_RESET_R                                       $22     !2, ->50
         35    > > FE_FETCH_R                                       ~23     $22, !3, ->50
         36    >   ASSIGN                                                   !4, ~23
   21    37        INIT_FCALL_BY_NAME                                       'isSame'
         38        CHECK_FUNC_ARG                                           
         39        FETCH_DIM_FUNC_ARG                               $25     !0, !4
         40        SEND_FUNC_ARG                                            $25
         41        CHECK_FUNC_ARG                                           
         42        FETCH_DIM_FUNC_ARG                               $26     !1, !4
         43        SEND_FUNC_ARG                                            $26
         44        DO_FCALL                                      0  $27     
         45        BOOL_NOT                                         ~28     $27
         46      > JMPZ                                                     ~28, ->49
   22    47    >   FE_FREE                                                  $22
         48      > RETURN                                                   <false>
   20    49    > > JMP                                                      ->35
         50    >   FE_FREE                                                  $22
   25    51      > RETURN                                                   <true>
   26    52*     > 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/s5l6e
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
-------------------------------------------------------------------------------------
   39     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   41     2        ISSET_ISEMPTY_CV                                 ~4      !0
          3        BOOL_NOT                                         ~5      ~4
          4      > JMPZ                                                     ~5, ->6
   42     5    >   ASSIGN                                                   !0, <array>
   43     6    >   TYPE_CHECK                                  128  ~7      !0
          7        BOOL_NOT                                         ~8      ~7
          8      > JMPZ                                                     ~8, ->11
   44     9    >   INIT_ARRAY                                       ~9      !0
         10        ASSIGN                                                   !0, ~9
   46    11    >   ISSET_ISEMPTY_CV                                 ~11     !1
         12        BOOL_NOT                                         ~12     ~11
         13      > JMPZ                                                     ~12, ->15
   47    14    >   ASSIGN                                                   !1, <array>
   48    15    >   TYPE_CHECK                                  128  ~14     !1
         16        BOOL_NOT                                         ~15     ~14
         17      > JMPZ                                                     ~15, ->20
   49    18    >   INIT_ARRAY                                       ~16     !1
         19        ASSIGN                                                   !1, ~16
   51    20    > > FE_RESET_R                                       $18     !1, ->38
         21    > > FE_FETCH_R                                       ~19     $18, !2, ->38
         22    >   ASSIGN                                                   !3, ~19
   52    23        ARRAY_KEY_EXISTS                                         !3, !0
         24      > JMPZ                                                     ~21, ->35
   53    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
   54    32    >   FE_FREE                                                  $18
         33      > RETURN                                                   <false>
         34    > > JMP                                                      ->37
   57    35    >   FE_FREE                                                  $18
         36      > RETURN                                                   <false>
   51    37    > > JMP                                                      ->21
         38    >   FE_FREE                                                  $18
   60    39      > RETURN                                                   <true>
   62    40*     > RETURN                                                   null

End of function hasallcapabilities

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
178.5 ms | 1410 KiB | 17 Q