3v4l.org

run code in 500+ 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 = 30
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 30
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 = 21
Branch analysis from position: 21
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 = 21
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
Branch analysis from position: 21
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
filename:       /in/9sgAf
function name:  test
number of ops:  32
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, ->30
          2    > > FE_FETCH_R                                           ~5      $4, !1, ->30
          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
   11    10      > JMP                                                          ->21
   13    11    >   TYPE_CHECK                                       64          !2
         12      > JMPZ                                                         ~12, ->21
   14    13    >   INIT_FCALL                                                   'sanitize_key'
         14        SEND_VAR                                                     !2
         15        DO_FCALL                                          0  $13     
         16        ROPE_INIT                                         3  ~15     'field%5B'
         17        ROPE_ADD                                          1  ~15     ~15, $13
         18        ROPE_END                                          2  ~14     ~15, '%5D'
         19        ASSIGN                                                       !3, ~14
   13    20      > JMP                                                          ->21
   19    21    >   INIT_FCALL                                                   'printf'
   20    22        SEND_VAL                                                     '%3Cinput+name%3D%22%25s%22+value%3D%221%22%2F%3E'
   21    23        INIT_FCALL                                                   'esc_attr'
         24        SEND_VAR                                                     !3
         25        DO_FCALL                                          0  $18     
         26        SEND_VAR                                                     $18
   19    27        DO_ICALL                                                     
   23    28        ECHO                                                         '%0A'
   10    29      > JMP                                                          ->2
         30    >   FE_FREE                                                      $4
   25    31      > RETURN                                                       null

End of function test

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
158.45 ms | 1441 KiB | 13 Q