3v4l.org

run code in 300+ PHP versions simultaneously
<?php function appendToValues(&$array, $value) { foreach ($array as &$item) { if ($item['attribute_code'] === 'harddisk') { $item['attribute_value'][] = $value; } elseif(is_array($item['attribute_value'])) { appendToValues($item['attribute_value'], $value); } } } $array = [ 3 => [ 'attribute_code' => 'category', 'attribute_value' => [ 4 => [ 'attribute_code' => 'hardware', 'attribute_value' => [ 5 => [ 'attribute_code' => 'harddisk', 'attribute_value' => [ 6 => [ 'attribute_code' => 'small', 'attribute_value' => '132gb', ], ], ], ], ], ], ], ]; var_dump($array); appendToValues($array, ['attribute_code' => 'medium', 'attribute_value' => '256gb']); var_dump($array);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/p5uav
function name:  (null)
number of ops:  12
compiled vars:  !0 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   ASSIGN                                                   !0, <array>
   36     1        INIT_FCALL                                               'var_dump'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                                 
   38     4        INIT_FCALL                                               'appendtovalues'
          5        SEND_REF                                                 !0
          6        SEND_VAL                                                 <array>
          7        DO_FCALL                                      0          
   40     8        INIT_FCALL                                               'var_dump'
          9        SEND_VAR                                                 !0
         10        DO_ICALL                                                 
         11      > RETURN                                                   1

Function appendtovalues:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 125) Position 1 = 3, Position 2 = 21
Branch analysis from position: 3
2 jumps found. (Code = 126) Position 1 = 4, Position 2 = 21
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 11
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 20
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 20
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
filename:       /in/p5uav
function name:  appendToValues
number of ops:  23
compiled vars:  !0 = $array, !1 = $value, !2 = $item
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    5     2      > FE_RESET_RW                                      $3      !0, ->21
          3    > > FE_FETCH_RW                                              $3, !2, ->21
    6     4    >   FETCH_DIM_R                                      ~4      !2, 'attribute_code'
          5        IS_IDENTICAL                                             ~4, 'harddisk'
          6      > JMPZ                                                     ~5, ->11
    7     7    >   FETCH_DIM_W                                      $6      !2, 'attribute_value'
          8        ASSIGN_DIM                                               $6
          9        OP_DATA                                                  !1
    6    10      > JMP                                                      ->20
    8    11    >   FETCH_DIM_R                                      ~8      !2, 'attribute_value'
         12        TYPE_CHECK                                  128          ~8
         13      > JMPZ                                                     ~9, ->20
    9    14    >   INIT_FCALL_BY_NAME                                       'appendToValues'
         15        CHECK_FUNC_ARG                                           
         16        FETCH_DIM_FUNC_ARG                               $10     !2, 'attribute_value'
         17        SEND_FUNC_ARG                                            $10
         18        SEND_VAR_EX                                              !1
         19        DO_FCALL                                      0          
    5    20    > > JMP                                                      ->3
         21    >   FE_FREE                                                  $3
   12    22      > RETURN                                                   null

End of function appendtovalues

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
144.02 ms | 1017 KiB | 15 Q