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]; } } $out = []; $skip = []; foreach ($results as $result) { foreach ($query_where as $where) { list($key, $comp, $value) = $where; if (!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; 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 = 18, Position 2 = 114
Branch analysis from position: 18
2 jumps found. (Code = 78) Position 1 = 19, Position 2 = 114
Branch analysis from position: 19
2 jumps found. (Code = 77) Position 1 = 20, Position 2 = 110
Branch analysis from position: 20
2 jumps found. (Code = 78) Position 1 = 21, Position 2 = 110
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 32, Position 2 = 36
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
Branch analysis from position: 36
5 jumps found. (Code = 188) Position 1 = 44, Position 2 = 64, Position 3 = 77, Position 4 = 109, Position 5 = 37
Branch analysis from position: 44
2 jumps found. (Code = 77) Position 1 = 47, Position 2 = 62
Branch analysis from position: 47
2 jumps found. (Code = 78) Position 1 = 48, Position 2 = 62
Branch analysis from position: 48
2 jumps found. (Code = 77) Position 1 = 49, Position 2 = 58
Branch analysis from position: 49
2 jumps found. (Code = 78) Position 1 = 50, Position 2 = 58
Branch analysis from position: 50
2 jumps found. (Code = 43) Position 1 = 54, Position 2 = 57
Branch analysis from position: 54
1 jumps found. (Code = 42) Position 1 = 47
Branch analysis from position: 47
Branch analysis from position: 57
1 jumps found. (Code = 42) Position 1 = 49
Branch analysis from position: 49
Branch analysis from position: 58
1 jumps found. (Code = 42) Position 1 = 62
Branch analysis from position: 62
1 jumps found. (Code = 42) Position 1 = 109
Branch analysis from position: 109
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
Branch analysis from position: 58
Branch analysis from position: 62
Branch analysis from position: 62
Branch analysis from position: 64
2 jumps found. (Code = 43) Position 1 = 67, Position 2 = 76
Branch analysis from position: 67
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
Branch analysis from position: 76
1 jumps found. (Code = 42) Position 1 = 109
Branch analysis from position: 109
Branch analysis from position: 77
2 jumps found. (Code = 43) Position 1 = 84, Position 2 = 86
Branch analysis from position: 84
2 jumps found. (Code = 43) Position 1 = 99, Position 2 = 108
Branch analysis from position: 99
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
Branch analysis from position: 108
1 jumps found. (Code = 42) Position 1 = 109
Branch analysis from position: 109
Branch analysis from position: 86
Branch analysis from position: 109
Branch analysis from position: 37
2 jumps found. (Code = 44) Position 1 = 39, Position 2 = 44
Branch analysis from position: 39
2 jumps found. (Code = 44) Position 1 = 41, Position 2 = 64
Branch analysis from position: 41
2 jumps found. (Code = 44) Position 1 = 43, Position 2 = 77
Branch analysis from position: 43
1 jumps found. (Code = 42) Position 1 = 109
Branch analysis from position: 109
Branch analysis from position: 77
Branch analysis from position: 64
Branch analysis from position: 44
Branch analysis from position: 110
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
Branch analysis from position: 110
Branch analysis from position: 114
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 114
Branch analysis from position: 14
Branch analysis from position: 15
filename:       /in/jlCfK
function name:  (null)
number of ops:  119
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    >   ASSIGN                                                   !5, <array>
   27    16        ASSIGN                                                   !6, <array>
   28    17      > FE_RESET_R                                       $25     !1, ->114
         18    > > FE_FETCH_R                                               $25, !7, ->114
   29    19    > > FE_RESET_R                                       $26     !4, ->110
         20    > > FE_FETCH_R                                               $26, !8, ->110
   30    21    >   QM_ASSIGN                                        ~27     !8
         22        FETCH_LIST_R                                     $28     ~27, 0
         23        ASSIGN                                                   !3, $28
         24        FETCH_LIST_R                                     $30     ~27, 1
         25        ASSIGN                                                   !9, $30
         26        FETCH_LIST_R                                     $32     ~27, 2
         27        ASSIGN                                                   !2, $32
         28        FREE                                                     ~27
   31    29        ISSET_ISEMPTY_DIM_OBJ                         0  ~34     !7, !3
         30        BOOL_NOT                                         ~35     ~34
         31      > JMPZ                                                     ~35, ->36
   32    32    >   INIT_ARRAY                                       ~36     '%21isset'
         33        ADD_ARRAY_ELEMENT                                ~36     !3
         34        ASSIGN                                                   !6, ~36
   33    35      > JMP                                                      ->20
   35    36    > > SWITCH_STRING                                            !9, [ '_OR':->44, '%3D':->64, 'LIKE':->77, ], ->109
   36    37    >   IS_EQUAL                                                 !9, '_OR'
         38      > JMPNZ                                                    ~38, ->44
   49    39    >   IS_EQUAL                                                 !9, '%3D'
         40      > JMPNZ                                                    ~38, ->64
   55    41    >   IS_EQUAL                                                 !9, 'LIKE'
         42      > JMPNZ                                                    ~38, ->77
         43    > > JMP                                                      ->109
   37    44    >   FETCH_DIM_R                                      ~39     !0, '_or'
         45        FETCH_DIM_R                                      ~40     ~39, !3
         46      > FE_RESET_R                                       $41     ~40, ->62
         47    > > FE_FETCH_R                                               $41, !10, ->62
   38    48    > > FE_RESET_R                                       $42     !10, ->58
         49    > > FE_FETCH_R                                       ~43     $42, !11, ->58
         50    >   ASSIGN                                                   !12, ~43
   39    51        FETCH_DIM_R                                      ~45     !7, !12
         52        IS_NOT_EQUAL                                             !11, ~45
         53      > JMPZ                                                     ~46, ->57
   40    54    >   ECHO                                                     1
   41    55        FE_FREE                                                  $42
         56      > JMP                                                      ->47
   38    57    > > JMP                                                      ->49
         58    >   FE_FREE                                                  $42
   45    59        ECHO                                                     2
   46    60      > JMP                                                      ->62
   37    61*       JMP                                                      ->47
         62    >   FE_FREE                                                  $41
   48    63      > JMP                                                      ->109
   50    64    >   FETCH_DIM_R                                      ~47     !7, !3
         65        IS_NOT_EQUAL                                             !2, ~47
         66      > JMPZ                                                     ~48, ->76
   51    67    >   FETCH_DIM_R                                      ~50     !7, !3
         68        INIT_ARRAY                                       ~51     ~50
         69        ADD_ARRAY_ELEMENT                                ~51     !2
         70        ADD_ARRAY_ELEMENT                                ~51     '%3D'
         71        ADD_ARRAY_ELEMENT                                ~51     !3
         72        ASSIGN_DIM                                               !6
         73        OP_DATA                                                  ~51
   52    74        FE_FREE                                                  $26
         75      > JMP                                                      ->18
   54    76    > > JMP                                                      ->109
   56    77    >   INIT_FCALL                                               'strpos'
         78        SEND_VAR                                                 !2
         79        SEND_VAL                                                 '%25'
         80        DO_ICALL                                         $52     
         81        ASSIGN                                                   !13, $52
   57    82        TYPE_CHECK                                    4          !13
         83      > JMPZ                                                     ~54, ->86
         84    >   STRLEN                                           ~55     !2
         85        ASSIGN                                                   !13, ~55
   58    86    >   INIT_FCALL                                               'substr'
         87        FETCH_DIM_R                                      ~57     !7, !3
         88        SEND_VAL                                                 ~57
         89        SEND_VAL                                                 0
         90        SEND_VAR                                                 !13
         91        DO_ICALL                                         $58     
         92        INIT_FCALL                                               'substr'
         93        SEND_VAR                                                 !2
         94        SEND_VAL                                                 0
         95        SEND_VAR                                                 !13
         96        DO_ICALL                                         $59     
         97        IS_NOT_IDENTICAL                                         $58, $59
         98      > JMPZ                                                     ~60, ->108
   59    99    >   FETCH_DIM_R                                      ~62     !7, !3
        100        INIT_ARRAY                                       ~63     ~62
        101        ADD_ARRAY_ELEMENT                                ~63     !2
        102        ADD_ARRAY_ELEMENT                                ~63     'LIKE'
        103        ADD_ARRAY_ELEMENT                                ~63     !3
        104        ASSIGN_DIM                                               !6
        105        OP_DATA                                                  ~63
   60   106        FE_FREE                                                  $26
        107      > JMP                                                      ->18
   62   108    > > JMP                                                      ->109
   29   109    > > JMP                                                      ->20
        110    >   FE_FREE                                                  $26
   66   111        ASSIGN_DIM                                               !5
        112        OP_DATA                                                  !7
   28   113      > JMP                                                      ->18
        114    >   FE_FREE                                                  $25
   68   115        INIT_FCALL                                               'var_dump'
        116        SEND_VAR                                                 !5
        117        DO_ICALL                                                 
        118      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
216.06 ms | 1408 KiB | 19 Q