3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = array( 'key1' => 'val1', 'key2' => 'val2', 'key3' => 'val3', 'key4' => array( 'subkey1' => 'subval1', 'subkey2' => 'subval2', ) ); function walkArray($input) { // Define our output array $output = array( 'keys' => '', 'vals' => '', 'children' => array(), ); // We're looping trough the input array foreach($input AS $key => $value) { // If the current value is an array we reached the next dimension if(is_array($value)) { // So we call walkArray() recursively with our current value // and assign the returned array to a new element in our $output's 'children' key $output['children'][] = walkArray($value); } else { // We'll concatenate our keys and values... $output['keys'] .= $key . ', '; $output['vals'] .= ':' . $value .', '; } } // And get rid of the trailing commas $output['keys'] = rtrim($output['keys'], ', '); $output['vals'] = rtrim($output['vals'], ', '); // Eventually we return our output array return $output; } ?> print_r(walkArray($arr));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/CL8mN
function name:  (null)
number of ops:  3
compiled vars:  !0 = $arr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
   48     1        ECHO                                                     '%0A++++print_r%28walkArray%28%24arr%29%29%3B'
   49     2      > RETURN                                                   1

Function walkarray:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 22
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 22
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 14
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
filename:       /in/CL8mN
function name:  walkArray
number of ops:  39
compiled vars:  !0 = $input, !1 = $output, !2 = $value, !3 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
   15     1        ASSIGN                                                   !1, <array>
   22     2      > FE_RESET_R                                       $5      !0, ->22
          3    > > FE_FETCH_R                                       ~6      $5, !2, ->22
          4    >   ASSIGN                                                   !3, ~6
   25     5        TYPE_CHECK                                  128          !2
          6      > JMPZ                                                     ~8, ->14
   29     7    >   INIT_FCALL_BY_NAME                                       'walkArray'
          8        SEND_VAR_EX                                              !2
          9        DO_FCALL                                      0  $11     
         10        FETCH_DIM_W                                      $9      !1, 'children'
         11        ASSIGN_DIM                                               $9
         12        OP_DATA                                                  $11
         13      > JMP                                                      ->21
   34    14    >   CONCAT                                           ~13     !3, '%2C+'
         15        ASSIGN_DIM_OP                .=               8          !1, 'keys'
         16        OP_DATA                                                  ~13
   35    17        CONCAT                                           ~15     '%3A', !2
         18        CONCAT                                           ~16     ~15, '%2C+'
         19        ASSIGN_DIM_OP                .=               8          !1, 'vals'
         20        OP_DATA                                                  ~16
   22    21    > > JMP                                                      ->3
         22    >   FE_FREE                                                  $5
   40    23        INIT_FCALL                                               'rtrim'
         24        FETCH_DIM_R                                      ~18     !1, 'keys'
         25        SEND_VAL                                                 ~18
         26        SEND_VAL                                                 '%2C+'
         27        DO_ICALL                                         $19     
         28        ASSIGN_DIM                                               !1, 'keys'
         29        OP_DATA                                                  $19
   41    30        INIT_FCALL                                               'rtrim'
         31        FETCH_DIM_R                                      ~21     !1, 'vals'
         32        SEND_VAL                                                 ~21
         33        SEND_VAL                                                 '%2C+'
         34        DO_ICALL                                         $22     
         35        ASSIGN_DIM                                               !1, 'vals'
         36        OP_DATA                                                  $22
   44    37      > RETURN                                                   !1
   45    38*     > RETURN                                                   null

End of function walkarray

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.78 ms | 1400 KiB | 15 Q