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

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.17 ms | 1408 KiB | 19 Q