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)) { $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 = 46
Branch analysis from position: 46
2 jumps found. (Code = 44) Position 1 = 49, Position 2 = 17
Branch analysis from position: 49
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 35
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 45
Branch analysis from position: 45
2 jumps found. (Code = 44) Position 1 = 49, Position 2 = 17
Branch analysis from position: 49
Branch analysis from position: 17
Branch analysis from position: 35
2 jumps found. (Code = 43) Position 1 = 37, Position 2 = 45
Branch analysis from position: 37
2 jumps found. (Code = 44) Position 1 = 49, Position 2 = 17
Branch analysis from position: 49
Branch analysis from position: 17
Branch analysis from position: 45
filename:       /in/qMKs3
function name:  (null)
number of ops:  53
compiled vars:  !0 = $keys, !1 = $sql, !2 = $str, !3 = $arr, !4 = $j, !5 = $out, !6 = $i
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                                         $9      
          7        ASSIGN                                                   !2, $9
   15     8        INIT_FCALL                                               'explode'
          9        SEND_VAL                                                 '+'
         10        SEND_VAR                                                 !2
         11        DO_ICALL                                         $11     
         12        ASSIGN                                                   !3, $11
   17    13        ASSIGN                                                   !4, -1
   18    14        ASSIGN                                                   !5, <array>
   19    15        ASSIGN                                                   !6, 0
         16      > JMP                                                      ->46
   20    17    >   INIT_FCALL                                               'in_array'
         18        INIT_FCALL                                               'strtoupper'
         19        FETCH_DIM_R                                      ~16     !3, !6
         20        SEND_VAL                                                 ~16
         21        DO_ICALL                                         $17     
         22        SEND_VAR                                                 $17
         23        SEND_VAR                                                 !0
         24        DO_ICALL                                         $18     
         25      > JMPZ                                                     $18, ->35
   21    26    >   PRE_INC                                                  !4
   22    27        FETCH_DIM_R                                      ~22     !3, !6
         28        FETCH_DIM_W                                      $20     !5, !4
         29        ASSIGN_DIM                                               $20, 0
         30        OP_DATA                                                  ~22
   23    31        FETCH_DIM_W                                      $23     !5, !4
         32        ASSIGN_DIM                                               $23, 1
         33        OP_DATA                                                  ''
   24    34      > JMP                                                      ->45
   26    35    >   IS_SMALLER                                               -1, !4
         36      > JMPZ                                                     ~25, ->45
   27    37    >   FETCH_DIM_R                                      ~28     !5, !4
         38        FETCH_DIM_R                                      ~29     ~28, 1
         39        FETCH_DIM_R                                      ~30     !3, !6
         40        CONCAT                                           ~31     ~29, ~30
         41        CONCAT                                           ~32     ~31, '+'
         42        FETCH_DIM_W                                      $26     !5, !4
         43        ASSIGN_DIM                                               $26, 1
         44        OP_DATA                                                  ~32
   19    45    >   PRE_INC                                                  !6
         46    >   COUNT                                            ~34     !3
         47        IS_SMALLER                                               !6, ~34
         48      > JMPNZ                                                    ~35, ->17
   31    49    >   INIT_FCALL                                               'var_dump'
         50        SEND_VAR                                                 !5
         51        DO_ICALL                                                 
         52      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
172.54 ms | 1400 KiB | 23 Q