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

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
171.93 ms | 1408 KiB | 19 Q