3v4l.org

run code in 300+ PHP versions simultaneously
<?php function expandArguments(&$query, &$args) { $modified = FALSE; foreach (array_filter($args, 'is_array') as $key => $data) { $new_keys = array(); foreach ($data as $i => $value) { $new_keys[$key . '_' . $i] = $value; } $query = preg_replace( '#' . $key . '\b#', implode(', ', array_keys($new_keys)), $query ); unset($args[$key]); $args += $new_keys; $modified = TRUE; } return $modified; } $query = "SELECT * FROM foo WHERE id IN (:ids)"; $args = array( 'ids' => array( 1, 2, 3 ) ); expandArguments($query, $args); var_dump($query, $args);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Gs8Nr
function name:  (null)
number of ops:  11
compiled vars:  !0 = $query, !1 = $args
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   ASSIGN                                                   !0, 'SELECT+%2A+FROM+foo+WHERE+id+IN+%28%3Aids%29'
   24     1        ASSIGN                                                   !1, <array>
   31     2        INIT_FCALL                                               'expandarguments'
          3        SEND_REF                                                 !0
          4        SEND_REF                                                 !1
          5        DO_FCALL                                      0          
   33     6        INIT_FCALL                                               'var_dump'
          7        SEND_VAR                                                 !0
          8        SEND_VAR                                                 !1
          9        DO_ICALL                                                 
         10      > RETURN                                                   1

Function expandarguments:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 39
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 39
Branch analysis from position: 9
2 jumps found. (Code = 77) Position 1 = 12, Position 2 = 19
Branch analysis from position: 12
2 jumps found. (Code = 78) Position 1 = 13, Position 2 = 19
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 19
Branch analysis from position: 39
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 39
filename:       /in/Gs8Nr
function name:  expandArguments
number of ops:  42
compiled vars:  !0 = $query, !1 = $args, !2 = $modified, !3 = $data, !4 = $key, !5 = $new_keys, !6 = $value, !7 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    4     2        ASSIGN                                                   !2, <false>
    5     3        INIT_FCALL                                               'array_filter'
          4        SEND_VAR                                                 !1
          5        SEND_VAL                                                 'is_array'
          6        DO_ICALL                                         $9      
          7      > FE_RESET_R                                       $10     $9, ->39
          8    > > FE_FETCH_R                                       ~11     $10, !3, ->39
          9    >   ASSIGN                                                   !4, ~11
    6    10        ASSIGN                                                   !5, <array>
    7    11      > FE_RESET_R                                       $14     !3, ->19
         12    > > FE_FETCH_R                                       ~15     $14, !6, ->19
         13    >   ASSIGN                                                   !7, ~15
    8    14        CONCAT                                           ~17     !4, '_'
         15        CONCAT                                           ~18     ~17, !7
         16        ASSIGN_DIM                                               !5, ~18
         17        OP_DATA                                                  !6
    7    18      > JMP                                                      ->12
         19    >   FE_FREE                                                  $14
   10    20        INIT_FCALL                                               'preg_replace'
   11    21        CONCAT                                           ~20     '%23', !4
         22        CONCAT                                           ~21     ~20, '%5Cb%23'
         23        SEND_VAL                                                 ~21
   12    24        INIT_FCALL                                               'implode'
         25        SEND_VAL                                                 '%2C+'
         26        INIT_FCALL                                               'array_keys'
         27        SEND_VAR                                                 !5
         28        DO_ICALL                                         $22     
         29        SEND_VAR                                                 $22
         30        DO_ICALL                                         $23     
         31        SEND_VAR                                                 $23
   13    32        SEND_VAR                                                 !0
         33        DO_ICALL                                         $24     
   10    34        ASSIGN                                                   !0, $24
   15    35        UNSET_DIM                                                !1, !4
   16    36        ASSIGN_OP                                     1          !1, !5
   17    37        ASSIGN                                                   !2, <true>
    5    38      > JMP                                                      ->8
         39    >   FE_FREE                                                  $10
   19    40      > RETURN                                                   !2
   20    41*     > RETURN                                                   null

End of function expandarguments

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.48 ms | 1403 KiB | 24 Q