3v4l.org

run code in 300+ PHP versions simultaneously
<?php $query_input = [ '_or'=>[[ ['cats'=>1], ['dogs'=>1] ]] ]; $results = [ ['id'=>0,'cats'=>0,'dogs'=>0], ['id'=>1,'cats'=>0,'dogs'=>0,'lizards'=>3], ['id'=>2,'cats'=>0,'dogs'=>1], ['id'=>3,'cats'=>1,'dogs'=>0], ['id'=>4,'cats'=>1,'dogs'=>1] ]; // hackkk both the filter and find methods need significant cleanup if (isset($query_input['_or'])) { foreach ($query_input['_or'] as $key=>$value) { $query_where[] = [$key, '_OR', null]; } } var_dump($query_where); $out = []; $skip = []; foreach ($results as $result) { foreach ($query_where as $where) { list($key, $comp, $value) = $where; if ($comp !== '_OR' && !isset($result[$key])) { $skip = ['!isset', $key]; continue; } // the data is not in the result, skip check switch ($comp) { case '_OR': foreach ($query_input['_or'][$key] as $or_item) { foreach ($or_item as $comp_key=>$comp_value) { if ($result[$comp_key] != $comp_value) { echo 1; continue(2); } } echo 2; var_dump($result,'okay'); break; // as long as the script hits here, the result will be kep } break; case '=': if ($result[$key] != $value) { $skip[] = [$result[$key],$value,'=',$key]; continue(3); } break; case 'LIKE': $pos = strpos($value,'%'); if ($pos===false) $pos = strlen($value); if (substr($result[$key],0,$pos) !== substr($value,0,$pos)) { $skip[] = [$result[$key],$value,'LIKE',$key]; continue(3); } break; } } $out[] = $result; } var_dump($out);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 15
Branch analysis from position: 4
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 14
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 14
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 14
2 jumps found. (Code = 77) Position 1 = 21, Position 2 = 124
Branch analysis from position: 21
2 jumps found. (Code = 78) Position 1 = 22, Position 2 = 124
Branch analysis from position: 22
2 jumps found. (Code = 77) Position 1 = 23, Position 2 = 120
Branch analysis from position: 23
2 jumps found. (Code = 78) Position 1 = 24, Position 2 = 120
Branch analysis from position: 24
2 jumps found. (Code = 46) Position 1 = 34, Position 2 = 37
Branch analysis from position: 34
2 jumps found. (Code = 43) Position 1 = 38, Position 2 = 42
Branch analysis from position: 38
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
Branch analysis from position: 42
5 jumps found. (Code = 188) Position 1 = 50, Position 2 = 74, Position 3 = 87, Position 4 = 119, Position 5 = 43
Branch analysis from position: 50
2 jumps found. (Code = 77) Position 1 = 53, Position 2 = 72
Branch analysis from position: 53
2 jumps found. (Code = 78) Position 1 = 54, Position 2 = 72
Branch analysis from position: 54
2 jumps found. (Code = 77) Position 1 = 55, Position 2 = 64
Branch analysis from position: 55
2 jumps found. (Code = 78) Position 1 = 56, Position 2 = 64
Branch analysis from position: 56
2 jumps found. (Code = 43) Position 1 = 60, Position 2 = 63
Branch analysis from position: 60
1 jumps found. (Code = 42) Position 1 = 53
Branch analysis from position: 53
Branch analysis from position: 63
1 jumps found. (Code = 42) Position 1 = 55
Branch analysis from position: 55
Branch analysis from position: 64
1 jumps found. (Code = 42) Position 1 = 72
Branch analysis from position: 72
1 jumps found. (Code = 42) Position 1 = 119
Branch analysis from position: 119
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
Branch analysis from position: 64
Branch analysis from position: 72
Branch analysis from position: 72
Branch analysis from position: 74
2 jumps found. (Code = 43) Position 1 = 77, Position 2 = 86
Branch analysis from position: 77
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
Branch analysis from position: 86
1 jumps found. (Code = 42) Position 1 = 119
Branch analysis from position: 119
Branch analysis from position: 87
2 jumps found. (Code = 43) Position 1 = 94, Position 2 = 96
Branch analysis from position: 94
2 jumps found. (Code = 43) Position 1 = 109, Position 2 = 118
Branch analysis from position: 109
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
Branch analysis from position: 118
1 jumps found. (Code = 42) Position 1 = 119
Branch analysis from position: 119
Branch analysis from position: 96
Branch analysis from position: 119
Branch analysis from position: 43
2 jumps found. (Code = 44) Position 1 = 45, Position 2 = 50
Branch analysis from position: 45
2 jumps found. (Code = 44) Position 1 = 47, Position 2 = 74
Branch analysis from position: 47
2 jumps found. (Code = 44) Position 1 = 49, Position 2 = 87
Branch analysis from position: 49
1 jumps found. (Code = 42) Position 1 = 119
Branch analysis from position: 119
Branch analysis from position: 87
Branch analysis from position: 74
Branch analysis from position: 50
Branch analysis from position: 37
Branch analysis from position: 120
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
Branch analysis from position: 120
Branch analysis from position: 124
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 124
Branch analysis from position: 14
Branch analysis from position: 15
filename:       /in/CavSa
function name:  (null)
number of ops:  129
compiled vars:  !0 = $query_input, !1 = $results, !2 = $value, !3 = $key, !4 = $query_where, !5 = $out, !6 = $skip, !7 = $result, !8 = $where, !9 = $comp, !10 = $or_item, !11 = $comp_value, !12 = $comp_key, !13 = $pos
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   10     1        ASSIGN                                                   !1, <array>
   19     2        ISSET_ISEMPTY_DIM_OBJ                         0          !0, '_or'
          3      > JMPZ                                                     ~16, ->15
   20     4    >   FETCH_DIM_R                                      ~17     !0, '_or'
          5      > FE_RESET_R                                       $18     ~17, ->14
          6    > > FE_FETCH_R                                       ~19     $18, !2, ->14
          7    >   ASSIGN                                                   !3, ~19
   21     8        INIT_ARRAY                                       ~22     !3
          9        ADD_ARRAY_ELEMENT                                ~22     '_OR'
         10        ADD_ARRAY_ELEMENT                                ~22     null
         11        ASSIGN_DIM                                               !4
         12        OP_DATA                                                  ~22
   20    13      > JMP                                                      ->6
         14    >   FE_FREE                                                  $18
   25    15    >   INIT_FCALL                                               'var_dump'
         16        SEND_VAR                                                 !4
         17        DO_ICALL                                                 
   26    18        ASSIGN                                                   !5, <array>
   28    19        ASSIGN                                                   !6, <array>
   29    20      > FE_RESET_R                                       $26     !1, ->124
         21    > > FE_FETCH_R                                               $26, !7, ->124
   30    22    > > FE_RESET_R                                       $27     !4, ->120
         23    > > FE_FETCH_R                                               $27, !8, ->120
   31    24    >   QM_ASSIGN                                        ~28     !8
         25        FETCH_LIST_R                                     $29     ~28, 0
         26        ASSIGN                                                   !3, $29
         27        FETCH_LIST_R                                     $31     ~28, 1
         28        ASSIGN                                                   !9, $31
         29        FETCH_LIST_R                                     $33     ~28, 2
         30        ASSIGN                                                   !2, $33
         31        FREE                                                     ~28
   32    32        IS_NOT_IDENTICAL                                 ~35     !9, '_OR'
         33      > JMPZ_EX                                          ~35     ~35, ->37
         34    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~36     !7, !3
         35        BOOL_NOT                                         ~37     ~36
         36        BOOL                                             ~35     ~37
         37    > > JMPZ                                                     ~35, ->42
   33    38    >   INIT_ARRAY                                       ~38     '%21isset'
         39        ADD_ARRAY_ELEMENT                                ~38     !3
         40        ASSIGN                                                   !6, ~38
   34    41      > JMP                                                      ->23
   36    42    > > SWITCH_STRING                                            !9, [ '_OR':->50, '%3D':->74, 'LIKE':->87, ], ->119
   37    43    >   IS_EQUAL                                                 !9, '_OR'
         44      > JMPNZ                                                    ~40, ->50
   52    45    >   IS_EQUAL                                                 !9, '%3D'
         46      > JMPNZ                                                    ~40, ->74
   58    47    >   IS_EQUAL                                                 !9, 'LIKE'
         48      > JMPNZ                                                    ~40, ->87
         49    > > JMP                                                      ->119
   38    50    >   FETCH_DIM_R                                      ~41     !0, '_or'
         51        FETCH_DIM_R                                      ~42     ~41, !3
         52      > FE_RESET_R                                       $43     ~42, ->72
         53    > > FE_FETCH_R                                               $43, !10, ->72
   40    54    > > FE_RESET_R                                       $44     !10, ->64
         55    > > FE_FETCH_R                                       ~45     $44, !11, ->64
         56    >   ASSIGN                                                   !12, ~45
   41    57        FETCH_DIM_R                                      ~47     !7, !12
         58        IS_NOT_EQUAL                                             !11, ~47
         59      > JMPZ                                                     ~48, ->63
   42    60    >   ECHO                                                     1
   43    61        FE_FREE                                                  $44
         62      > JMP                                                      ->53
   40    63    > > JMP                                                      ->55
         64    >   FE_FREE                                                  $44
   47    65        ECHO                                                     2
   48    66        INIT_FCALL                                               'var_dump'
         67        SEND_VAR                                                 !7
         68        SEND_VAL                                                 'okay'
         69        DO_ICALL                                                 
   49    70      > JMP                                                      ->72
   38    71*       JMP                                                      ->53
         72    >   FE_FREE                                                  $43
   51    73      > JMP                                                      ->119
   53    74    >   FETCH_DIM_R                                      ~50     !7, !3
         75        IS_NOT_EQUAL                                             !2, ~50
         76      > JMPZ                                                     ~51, ->86
   54    77    >   FETCH_DIM_R                                      ~53     !7, !3
         78        INIT_ARRAY                                       ~54     ~53
         79        ADD_ARRAY_ELEMENT                                ~54     !2
         80        ADD_ARRAY_ELEMENT                                ~54     '%3D'
         81        ADD_ARRAY_ELEMENT                                ~54     !3
         82        ASSIGN_DIM                                               !6
         83        OP_DATA                                                  ~54
   55    84        FE_FREE                                                  $27
         85      > JMP                                                      ->21
   57    86    > > JMP                                                      ->119
   59    87    >   INIT_FCALL                                               'strpos'
         88        SEND_VAR                                                 !2
         89        SEND_VAL                                                 '%25'
         90        DO_ICALL                                         $55     
         91        ASSIGN                                                   !13, $55
   60    92        TYPE_CHECK                                    4          !13
         93      > JMPZ                                                     ~57, ->96
         94    >   STRLEN                                           ~58     !2
         95        ASSIGN                                                   !13, ~58
   61    96    >   INIT_FCALL                                               'substr'
         97        FETCH_DIM_R                                      ~60     !7, !3
         98        SEND_VAL                                                 ~60
         99        SEND_VAL                                                 0
        100        SEND_VAR                                                 !13
        101        DO_ICALL                                         $61     
        102        INIT_FCALL                                               'substr'
        103        SEND_VAR                                                 !2
        104        SEND_VAL                                                 0
        105        SEND_VAR                                                 !13
        106        DO_ICALL                                         $62     
        107        IS_NOT_IDENTICAL                                         $61, $62
        108      > JMPZ                                                     ~63, ->118
   62   109    >   FETCH_DIM_R                                      ~65     !7, !3
        110        INIT_ARRAY                                       ~66     ~65
        111        ADD_ARRAY_ELEMENT                                ~66     !2
        112        ADD_ARRAY_ELEMENT                                ~66     'LIKE'
        113        ADD_ARRAY_ELEMENT                                ~66     !3
        114        ASSIGN_DIM                                               !6
        115        OP_DATA                                                  ~66
   63   116        FE_FREE                                                  $27
        117      > JMP                                                      ->21
   65   118    > > JMP                                                      ->119
   30   119    > > JMP                                                      ->23
        120    >   FE_FREE                                                  $27
   69   121        ASSIGN_DIM                                               !5
        122        OP_DATA                                                  !7
   29   123      > JMP                                                      ->21
        124    >   FE_FREE                                                  $26
   71   125        INIT_FCALL                                               'var_dump'
        126        SEND_VAR                                                 !5
        127        DO_ICALL                                                 
        128      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.97 ms | 1408 KiB | 19 Q