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

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
180.37 ms | 1408 KiB | 19 Q