3v4l.org

run code in 300+ PHP versions simultaneously
<?php function esc_attr( $string ) { return $string; } function sanitize_key( $key ) { return $key; } function test( $choices ) { foreach( $choices as $key => $value ) { if ( is_integer( $key ) ) { $field_name = "field[$key]"; } elseif ( is_string( $key ) ) { $field_name = sprintf( 'field[%s]', sanitize_key( $key ) ); } else { // may want to throw an error here. } printf( '<input name="%s" value="1"/>', esc_attr( $field_name ) ); echo "\n"; } } echo "An indexed array\n"; $choices = array( 'Red', 'Blue', 'Green' ); test( $choices ); echo "\n\nAssociative array\n"; $choices = array( 'red' => 'Red', 'blue' => 'Blue', 'green' => 'Green' ); test( $choices );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9sgAf
function name:  (null)
number of ops:  11
compiled vars:  !0 = $choices
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   ECHO                                                     'An+indexed+array%0A'
   28     1        ASSIGN                                                   !0, <array>
   29     2        INIT_FCALL                                               'test'
          3        SEND_VAR                                                 !0
          4        DO_FCALL                                      0          
   31     5        ECHO                                                     '%0A%0AAssociative+array%0A'
   32     6        ASSIGN                                                   !0, <array>
   33     7        INIT_FCALL                                               'test'
          8        SEND_VAR                                                 !0
          9        DO_FCALL                                      0          
         10      > RETURN                                                   1

Function esc_attr:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9sgAf
function name:  esc_attr
number of ops:  3
compiled vars:  !0 = $string
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
    3     1      > RETURN                                                   !0
    4     2*     > RETURN                                                   null

End of function esc_attr

Function sanitize_key:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9sgAf
function name:  sanitize_key
number of ops:  3
compiled vars:  !0 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
    6     1      > RETURN                                                   !0
    7     2*     > RETURN                                                   null

End of function sanitize_key

Function test:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 31
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 31
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 11
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 22
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
Branch analysis from position: 22
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 31
filename:       /in/9sgAf
function name:  test
number of ops:  33
compiled vars:  !0 = $choices, !1 = $value, !2 = $key, !3 = $field_name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
   10     1      > FE_RESET_R                                       $4      !0, ->31
          2    > > FE_FETCH_R                                       ~5      $4, !1, ->31
          3    >   ASSIGN                                                   !2, ~5
   11     4        TYPE_CHECK                                   16          !2
          5      > JMPZ                                                     ~7, ->11
   12     6    >   ROPE_INIT                                     3  ~9      'field%5B'
          7        ROPE_ADD                                      1  ~9      ~9, !2
          8        ROPE_END                                      2  ~8      ~9, '%5D'
          9        ASSIGN                                                   !3, ~8
         10      > JMP                                                      ->22
   13    11    >   TYPE_CHECK                                   64          !2
         12      > JMPZ                                                     ~12, ->22
   14    13    >   INIT_FCALL                                               'sprintf'
         14        SEND_VAL                                                 'field%5B%25s%5D'
         15        INIT_FCALL                                               'sanitize_key'
         16        SEND_VAR                                                 !2
         17        DO_FCALL                                      0  $13     
         18        SEND_VAR                                                 $13
         19        DO_ICALL                                         $14     
         20        ASSIGN                                                   !3, $14
         21      > JMP                                                      ->22
   19    22    >   INIT_FCALL                                               'printf'
   20    23        SEND_VAL                                                 '%3Cinput+name%3D%22%25s%22+value%3D%221%22%2F%3E'
   21    24        INIT_FCALL                                               'esc_attr'
         25        SEND_VAR                                                 !3
         26        DO_FCALL                                      0  $16     
         27        SEND_VAR                                                 $16
         28        DO_ICALL                                                 
   23    29        ECHO                                                     '%0A'
   10    30      > JMP                                                      ->2
         31    >   FE_FREE                                                  $4
   25    32      > RETURN                                                   null

End of function test

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.83 ms | 1403 KiB | 21 Q