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

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.86 ms | 1400 KiB | 19 Q