3v4l.org

run code in 300+ PHP versions simultaneously
<?php $yaml = [ 'components' => [ [ 'cachet' => [ 'componentgroup' => 'Bar', 'componentname' => 'Name1' ] ], [ 'cachet' => [ 'componentgroup' => 'Bar', 'componentname' => 'Name2' ] ] ] ]; $yamlMap = []; foreach ($yaml['components'] as $yamlComponent) { $key = $yamlComponent['cachet']['componentgroup']; $value = $yamlComponent['cachet']['componentname']; // Lets initialize the key to be an array so that we may collect multiple values if(!array_key_exists($key, $yamlMap)) { $yamlMap[$key] = []; } // lets add the value to the map under the key $yamlMap[$key][] = $value; } var_dump($yamlMap);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 20
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 20
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 16
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 16
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
filename:       /in/FtjQC
function name:  (null)
number of ops:  25
compiled vars:  !0 = $yaml, !1 = $yamlMap, !2 = $yamlComponent, !3 = $key, !4 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   20     1        ASSIGN                                                   !1, <array>
   21     2        FETCH_DIM_R                                      ~7      !0, 'components'
          3      > FE_RESET_R                                       $8      ~7, ->20
          4    > > FE_FETCH_R                                               $8, !2, ->20
   22     5    >   FETCH_DIM_R                                      ~9      !2, 'cachet'
          6        FETCH_DIM_R                                      ~10     ~9, 'componentgroup'
          7        ASSIGN                                                   !3, ~10
   23     8        FETCH_DIM_R                                      ~12     !2, 'cachet'
          9        FETCH_DIM_R                                      ~13     ~12, 'componentname'
         10        ASSIGN                                                   !4, ~13
   25    11        ARRAY_KEY_EXISTS                                 ~15     !3, !1
         12        BOOL_NOT                                         ~16     ~15
         13      > JMPZ                                                     ~16, ->16
   26    14    >   ASSIGN_DIM                                               !1, !3
         15        OP_DATA                                                  <array>
   29    16    >   FETCH_DIM_W                                      $18     !1, !3
         17        ASSIGN_DIM                                               $18
         18        OP_DATA                                                  !4
   21    19      > JMP                                                      ->4
         20    >   FE_FREE                                                  $8
   32    21        INIT_FCALL                                               'var_dump'
         22        SEND_VAR                                                 !1
         23        DO_ICALL                                                 
         24      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
340.05 ms | 1010 KiB | 14 Q