3v4l.org

run code in 300+ PHP versions simultaneously
<?php $keys = array('SELECT','FROM','WHERE','LEFT','ORDER'); $sql = "Select id, nome FROM table as t WHERE t.id = 123 LEFT JOIN t2 ON t2.id = t.id ORDER BY t.name "; $str = preg_replace('!\s+!', ' ', $sql); $arr = explode(' ', $str); $j = -1; $out = []; for ($i = 0; $i < count($arr); $i++) { if (in_array(strtoupper($arr[$i]), $keys)) { if(($kw = array_search(strtoupper($arr[$i]), $keys)) !== false) { unset($keys[$kw]); } $j++; $out[$j][0] = $arr[$i]; $out[$j][1] = ''; continue; } if ($j > -1) { $out[$j][1] = $out[$j][1] . $arr[$i] . ' '; } } var_dump($out);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 58
Branch analysis from position: 58
2 jumps found. (Code = 44) Position 1 = 61, Position 2 = 17
Branch analysis from position: 61
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 47
Branch analysis from position: 26
2 jumps found. (Code = 43) Position 1 = 37, Position 2 = 38
Branch analysis from position: 37
1 jumps found. (Code = 42) Position 1 = 57
Branch analysis from position: 57
2 jumps found. (Code = 44) Position 1 = 61, Position 2 = 17
Branch analysis from position: 61
Branch analysis from position: 17
Branch analysis from position: 38
Branch analysis from position: 47
2 jumps found. (Code = 43) Position 1 = 49, Position 2 = 57
Branch analysis from position: 49
2 jumps found. (Code = 44) Position 1 = 61, Position 2 = 17
Branch analysis from position: 61
Branch analysis from position: 17
Branch analysis from position: 57
filename:       /in/VHNut
function name:  (null)
number of ops:  65
compiled vars:  !0 = $keys, !1 = $sql, !2 = $str, !3 = $arr, !4 = $j, !5 = $out, !6 = $i, !7 = $kw
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    5     1        ASSIGN                                                   !1, 'Select+%0A++++++++++++id%2C+%0A++++++++++++nome+%0A++++++++FROM+table+as+t+%0A++++++++WHERE+t.id+%3D+123+%0A++++++++++++LEFT+JOIN+t2+ON+t2.id+%3D+t.id+%0A++++++++ORDER+BY+t.name%0A++++++++'
   14     2        INIT_FCALL                                               'preg_replace'
          3        SEND_VAL                                                 '%21%5Cs%2B%21'
          4        SEND_VAL                                                 '+'
          5        SEND_VAR                                                 !1
          6        DO_ICALL                                         $10     
          7        ASSIGN                                                   !2, $10
   15     8        INIT_FCALL                                               'explode'
          9        SEND_VAL                                                 '+'
         10        SEND_VAR                                                 !2
         11        DO_ICALL                                         $12     
         12        ASSIGN                                                   !3, $12
   17    13        ASSIGN                                                   !4, -1
   18    14        ASSIGN                                                   !5, <array>
   19    15        ASSIGN                                                   !6, 0
         16      > JMP                                                      ->58
   20    17    >   INIT_FCALL                                               'in_array'
         18        INIT_FCALL                                               'strtoupper'
         19        FETCH_DIM_R                                      ~17     !3, !6
         20        SEND_VAL                                                 ~17
         21        DO_ICALL                                         $18     
         22        SEND_VAR                                                 $18
         23        SEND_VAR                                                 !0
         24        DO_ICALL                                         $19     
         25      > JMPZ                                                     $19, ->47
   21    26    >   INIT_FCALL                                               'array_search'
         27        INIT_FCALL                                               'strtoupper'
         28        FETCH_DIM_R                                      ~20     !3, !6
         29        SEND_VAL                                                 ~20
         30        DO_ICALL                                         $21     
         31        SEND_VAR                                                 $21
         32        SEND_VAR                                                 !0
         33        DO_ICALL                                         $22     
         34        ASSIGN                                           ~23     !7, $22
         35        TYPE_CHECK                                  1018          ~23
         36      > JMPZ                                                     ~24, ->38
   22    37    >   UNSET_DIM                                                !0, !7
   24    38    >   PRE_INC                                                  !4
   25    39        FETCH_DIM_R                                      ~28     !3, !6
         40        FETCH_DIM_W                                      $26     !5, !4
         41        ASSIGN_DIM                                               $26, 0
         42        OP_DATA                                                  ~28
   26    43        FETCH_DIM_W                                      $29     !5, !4
         44        ASSIGN_DIM                                               $29, 1
         45        OP_DATA                                                  ''
   27    46      > JMP                                                      ->57
   29    47    >   IS_SMALLER                                               -1, !4
         48      > JMPZ                                                     ~31, ->57
   30    49    >   FETCH_DIM_R                                      ~34     !5, !4
         50        FETCH_DIM_R                                      ~35     ~34, 1
         51        FETCH_DIM_R                                      ~36     !3, !6
         52        CONCAT                                           ~37     ~35, ~36
         53        CONCAT                                           ~38     ~37, '+'
         54        FETCH_DIM_W                                      $32     !5, !4
         55        ASSIGN_DIM                                               $32, 1
         56        OP_DATA                                                  ~38
   19    57    >   PRE_INC                                                  !6
         58    >   COUNT                                            ~40     !3
         59        IS_SMALLER                                               !6, ~40
         60      > JMPNZ                                                    ~41, ->17
   34    61    >   INIT_FCALL                                               'var_dump'
         62        SEND_VAR                                                 !5
         63        DO_ICALL                                                 
         64      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
178.13 ms | 1405 KiB | 25 Q