3v4l.org

run code in 300+ 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 = 28, Position 2 = 30
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
filename:       /in/DigL7
function name:  Item_Search
number of ops:  46
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        INIT_FCALL                                               'implode'
         16        SEND_VAL                                                 '%27%2C%27'
         17        SEND_VAR                                                 !4
         18        DO_ICALL                                         $17     
         19        CONCAT                                           ~18     '%27', $17
         20        CONCAT                                           ~19     ~18, '%27'
         21        ASSIGN                                                   !4, ~19
   20    22        INIT_FCALL                                               'array_sum'
         23        SEND_VAR                                                 !2
         24        DO_ICALL                                         $21     
         25        COUNT                                            ~22     !2
         26        IS_EQUAL                                                 $21, ~22
         27      > JMPZ                                                     ~23, ->30
         28    >   QM_ASSIGN                                        ~24     'OR+wear+%3D+%27%27'
         29      > JMP                                                      ->31
         30    >   QM_ASSIGN                                        ~24     ''
         31    >   ASSIGN                                                   !7, ~24
   22    32        INIT_FCALL                                               'query'
   23    33        ROPE_INIT                                     9  ~27     'SELECT+%2A+%0AFROM+items+%0AWHERE+appid%3D'
   25    34        ROPE_ADD                                      1  ~27     ~27, !0
         35        ROPE_ADD                                      2  ~27     ~27, '+%0A++AND+name+LIKE+%27%25'
   26    36        ROPE_ADD                                      3  ~27     ~27, !1
         37        ROPE_ADD                                      4  ~27     ~27, '%25%27%0A++AND+%28wear+IN+%28'
   27    38        ROPE_ADD                                      5  ~27     ~27, !4
         39        ROPE_ADD                                      6  ~27     ~27, '%29+'
         40        ROPE_ADD                                      7  ~27     ~27, !7
         41        ROPE_END                                      8  ~26     ~27, '%29'
         42        SEND_VAL                                                 ~26
   22    43        DO_FCALL                                      0  $32     
         44        ASSIGN                                                   !8, $32
   30    45      > RETURN                                                   null

End of function item_search

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
231.28 ms | 1006 KiB | 18 Q