3v4l.org

run code in 500+ PHP versions simultaneously
<?php function Query($str) { echo "$str\n"; } function Item_Search($AppID, $Keyword = '', $Wears) { // expected $Wears = [1,0,1,0,1] , numbers can be different from 0 to 1 $WearNames = ['red', 'green', 'blue', 'yellow', 'black']; $FinalWear = []; foreach ($Wears as $i => $Wear) { if ($Wear == 1) { $FinalWear[] = $WearNames[$i]; } } $FinalWear = "'" . implode("','", $FinalWear) . "'"; $EmptyWear = array_sum($Wears) == count($Wears) ? "OR wear = ''" : ''; $ItemList = Query(<<<EOD SELECT * FROM items WHERE appid=$AppID AND name LIKE '%$Keyword%' AND (wear IN ($FinalWear) $EmptyWear) EOD ); } Item_Search(4, 'shirt', [1, 0, 1, 0, 1]); Item_Search(13, 'shoe', [1, 1, 1, 1, 1]);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/DigL7
function name:  (null)
number of ops:  11
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   32     0  E >   INIT_FCALL                                                   'item_search'
          1        SEND_VAL                                                     4
          2        SEND_VAL                                                     'shirt'
          3        SEND_VAL                                                     <array>
          4        DO_FCALL                                          0          
   33     5        INIT_FCALL                                                   'item_search'
          6        SEND_VAL                                                     13
          7        SEND_VAL                                                     'shoe'
          8        SEND_VAL                                                     <array>
          9        DO_FCALL                                          0          
         10      > RETURN                                                       1

Function query:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/DigL7
function name:  Query
number of ops:  5
compiled vars:  !0 = $str
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   RECV                                                 !0      
    4     1        NOP                                                          
          2        FAST_CONCAT                                          ~1      !0, '%0A'
          3        ECHO                                                         ~1
    5     4      > RETURN                                                       null

End of function query

Function item_search:
Finding entry points
Branch analysis from position: 0
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
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 13
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 13
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 27
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
filename:       /in/DigL7
function name:  Item_Search
number of ops:  43
compiled vars:  !0 = $AppID, !1 = $Keyword, !2 = $Wears, !3 = $WearNames, !4 = $FinalWear, !5 = $Wear, !6 = $i, !7 = $EmptyWear, !8 = $ItemList
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    7     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        RECV                                                 !2      
   11     3        ASSIGN                                                       !3, <array>
   12     4        ASSIGN                                                       !4, <array>
   14     5      > FE_RESET_R                                           $11     !2, ->14
          6    > > FE_FETCH_R                                           ~12     $11, !5, ->14
          7    >   ASSIGN                                                       !6, ~12
   15     8        IS_EQUAL                                                     !5, 1
          9      > JMPZ                                                         ~14, ->13
   16    10    >   FETCH_DIM_R                                          ~16     !3, !6
         11        ASSIGN_DIM                                                   !4
         12        OP_DATA                                                      ~16
   14    13    > > JMP                                                          ->6
         14    >   FE_FREE                                                      $11
   19    15        FRAMELESS_ICALL_2                implode             ~17     '%27%2C%27', !4
         16        CONCAT                                               ~18     '%27', ~17
         17        CONCAT                                               ~19     ~18, '%27'
         18        ASSIGN                                                       !4, ~19
   20    19        INIT_FCALL                                                   'array_sum'
         20        SEND_VAR                                                     !2
         21        DO_ICALL                                             $21     
         22        COUNT                                                ~22     !2
         23        IS_EQUAL                                                     $21, ~22
         24      > JMPZ                                                         ~23, ->27
         25    >   QM_ASSIGN                                            ~24     'OR+wear+%3D+%27%27'
         26      > JMP                                                          ->28
         27    >   QM_ASSIGN                                            ~24     ''
         28    >   ASSIGN                                                       !7, ~24
   22    29        INIT_FCALL                                                   'query'
   23    30        ROPE_INIT                                         9  ~27     'SELECT+%2A+%0AFROM+items+%0AWHERE+appid%3D'
   25    31        ROPE_ADD                                          1  ~27     ~27, !0
         32        ROPE_ADD                                          2  ~27     ~27, '+%0A++AND+name+LIKE+%27%25'
   26    33        ROPE_ADD                                          3  ~27     ~27, !1
         34        ROPE_ADD                                          4  ~27     ~27, '%25%27%0A++AND+%28wear+IN+%28'
   27    35        ROPE_ADD                                          5  ~27     ~27, !4
         36        ROPE_ADD                                          6  ~27     ~27, '%29+'
         37        ROPE_ADD                                          7  ~27     ~27, !7
         38        ROPE_END                                          8  ~26     ~27, '%29'
         39        SEND_VAL                                                     ~26
   22    40        DO_FCALL                                          0  $32     
         41        ASSIGN                                                       !8, $32
   30    42      > RETURN                                                       null

End of function item_search

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
170.55 ms | 2178 KiB | 17 Q