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; continue(2); 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 = 122
Branch analysis from position: 21
2 jumps found. (Code = 78) Position 1 = 22, Position 2 = 122
Branch analysis from position: 22
2 jumps found. (Code = 77) Position 1 = 23, Position 2 = 118
Branch analysis from position: 23
2 jumps found. (Code = 78) Position 1 = 24, Position 2 = 118
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 = 72, Position 3 = 85, Position 4 = 117, Position 5 = 43
Branch analysis from position: 50
2 jumps found. (Code = 77) Position 1 = 53, Position 2 = 70
Branch analysis from position: 53
2 jumps found. (Code = 78) Position 1 = 54, Position 2 = 70
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 = 117
Branch analysis from position: 117
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
Branch analysis from position: 64
Branch analysis from position: 70
1 jumps found. (Code = 42) Position 1 = 117
Branch analysis from position: 117
Branch analysis from position: 70
Branch analysis from position: 72
2 jumps found. (Code = 43) Position 1 = 75, Position 2 = 84
Branch analysis from position: 75
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
Branch analysis from position: 84
1 jumps found. (Code = 42) Position 1 = 117
Branch analysis from position: 117
Branch analysis from position: 85
2 jumps found. (Code = 43) Position 1 = 92, Position 2 = 94
Branch analysis from position: 92
2 jumps found. (Code = 43) Position 1 = 107, Position 2 = 116
Branch analysis from position: 107
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
Branch analysis from position: 116
1 jumps found. (Code = 42) Position 1 = 117
Branch analysis from position: 117
Branch analysis from position: 94
Branch analysis from position: 117
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 = 72
Branch analysis from position: 47
2 jumps found. (Code = 44) Position 1 = 49, Position 2 = 85
Branch analysis from position: 49
1 jumps found. (Code = 42) Position 1 = 117
Branch analysis from position: 117
Branch analysis from position: 85
Branch analysis from position: 72
Branch analysis from position: 50
Branch analysis from position: 37
Branch analysis from position: 118
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
Branch analysis from position: 118
Branch analysis from position: 122
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 122
Branch analysis from position: 14
Branch analysis from position: 15
filename:       /in/VZCQL
function name:  (null)
number of ops:  127
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, ->122
         21    > > FE_FETCH_R                                               $26, !7, ->122
   30    22    > > FE_RESET_R                                       $27     !4, ->118
         23    > > FE_FETCH_R                                               $27, !8, ->118
   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':->72, 'LIKE':->85, ], ->117
   37    43    >   IS_EQUAL                                                 !9, '_OR'
         44      > JMPNZ                                                    ~40, ->50
   52    45    >   IS_EQUAL                                                 !9, '%3D'
         46      > JMPNZ                                                    ~40, ->72
   58    47    >   IS_EQUAL                                                 !9, 'LIKE'
         48      > JMPNZ                                                    ~40, ->85
         49    > > JMP                                                      ->117
   38    50    >   FETCH_DIM_R                                      ~41     !0, '_or'
         51        FETCH_DIM_R                                      ~42     ~41, !3
         52      > FE_RESET_R                                       $43     ~42, ->70
         53    > > FE_FETCH_R                                               $43, !10, ->70
   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        FE_FREE                                                  $43
         67      > JMP                                                      ->117
   49    68*       JMP                                                      ->70
   38    69*       JMP                                                      ->53
         70    >   FE_FREE                                                  $43
   51    71      > JMP                                                      ->117
   53    72    >   FETCH_DIM_R                                      ~49     !7, !3
         73        IS_NOT_EQUAL                                             !2, ~49
         74      > JMPZ                                                     ~50, ->84
   54    75    >   FETCH_DIM_R                                      ~52     !7, !3
         76        INIT_ARRAY                                       ~53     ~52
         77        ADD_ARRAY_ELEMENT                                ~53     !2
         78        ADD_ARRAY_ELEMENT                                ~53     '%3D'
         79        ADD_ARRAY_ELEMENT                                ~53     !3
         80        ASSIGN_DIM                                               !6
         81        OP_DATA                                                  ~53
   55    82        FE_FREE                                                  $27
         83      > JMP                                                      ->21
   57    84    > > JMP                                                      ->117
   59    85    >   INIT_FCALL                                               'strpos'
         86        SEND_VAR                                                 !2
         87        SEND_VAL                                                 '%25'
         88        DO_ICALL                                         $54     
         89        ASSIGN                                                   !13, $54
   60    90        TYPE_CHECK                                    4          !13
         91      > JMPZ                                                     ~56, ->94
         92    >   STRLEN                                           ~57     !2
         93        ASSIGN                                                   !13, ~57
   61    94    >   INIT_FCALL                                               'substr'
         95        FETCH_DIM_R                                      ~59     !7, !3
         96        SEND_VAL                                                 ~59
         97        SEND_VAL                                                 0
         98        SEND_VAR                                                 !13
         99        DO_ICALL                                         $60     
        100        INIT_FCALL                                               'substr'
        101        SEND_VAR                                                 !2
        102        SEND_VAL                                                 0
        103        SEND_VAR                                                 !13
        104        DO_ICALL                                         $61     
        105        IS_NOT_IDENTICAL                                         $60, $61
        106      > JMPZ                                                     ~62, ->116
   62   107    >   FETCH_DIM_R                                      ~64     !7, !3
        108        INIT_ARRAY                                       ~65     ~64
        109        ADD_ARRAY_ELEMENT                                ~65     !2
        110        ADD_ARRAY_ELEMENT                                ~65     'LIKE'
        111        ADD_ARRAY_ELEMENT                                ~65     !3
        112        ASSIGN_DIM                                               !6
        113        OP_DATA                                                  ~65
   63   114        FE_FREE                                                  $27
        115      > JMP                                                      ->21
   65   116    > > JMP                                                      ->117
   30   117    > > JMP                                                      ->23
        118    >   FE_FREE                                                  $27
   69   119        ASSIGN_DIM                                               !5
        120        OP_DATA                                                  !7
   29   121      > JMP                                                      ->21
        122    >   FE_FREE                                                  $26
   71   123        INIT_FCALL                                               'var_dump'
        124        SEND_VAR                                                 !5
        125        DO_ICALL                                                 
        126      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.75 ms | 1408 KiB | 19 Q