3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array= [ ['name' => 'block.0.name', 'value' => 'vda'], ['name' => 'block.0.backingIndex', 'value' => 2], ['name' => 'block.0.rd.reqs', 'value' => 248907], ['name' => 'block.0.rd.bytes', 'value' => 9842014208], ['name' => 'block.0.rd.times', 'value' => 372870570891], ['name' => 'block.1.name', 'value' => 'hda'], ['name' => 'block.1.backingIndex', 'value' => 30], ['name' => 'block.1.rd.reqs', 'value' => 2871], ['name' => 'block.1.rd.bytes', 'value' => 9677156], ['name' => 'block.1.rd.times', 'value' => 620637479], ['name' => 'block.2.name', 'value' => 'cda'], ['name' => 'block.2.backingIndex', 'value' => 30], ['name' => 'block.2.rd.reqs', 'value' => 2871], ['name' => 'block.2.rd.bytes', 'value' => 9677156], ['name' => 'block.2.rd.times', 'value' => 620637479], ['name' => 'vcpu.0.state', 'value' => 1], ['name' => 'vcpu.0.time', 'value' => 963654400000000], ['name' => 'vcpu.0.wait', 'value' => 0], ['name' => 'vcpu.1.state', 'value' => 1], ['name' => 'vcpu.1.time', 'value' => 936409070000000], ['name' => 'vcpu.1.wait', 'value' => 0], ['name' => 'vcpu.2.state', 'value' => 1], ['name' => 'vcpu.2.time', 'value' => 943396180000000], ['name' => 'vcpu.2.wait', 'value' => 0], ['name' => 'vcpu.3.state', 'value' => 1], ['name' => 'vcpu.3.time', 'value' => 959496330000000], ['name' => 'vcpu.3.wait', 'value' => 0], ['name' => 'balloon.current', 'value' => 16777216], ['name' => 'balloon.maximum', 'value' => 34534530], ['name' => 'balloon.swap_in', 'value' => 0], ['name' => 'balloon.swap_out', 'value' => 0], ['name' => 'balloon.major_fault', 'value' => 262], ['name' => 'balloon.minor_fault', 'value' => 132293], ['name' => 'balloon.unused', 'value' => 16153712], ['name' => 'balloon.available', 'value' => 16396312], ]; $result = []; foreach ($array as ['name' => $name, 'value' => $value]) { $parts = explode('.', $name); $parentKey = $parts[0] . 's'; $childKey = implode(array_splice($parts, 0, ctype_digit($parts[1]) ? 2 : 1)); $grandchildKey = implode('.', $parts); if ($grandchildKey !== 'name') { $result[$parentKey][$childKey][$grandchildKey] = $value; } } var_export($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 46
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 46
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 28
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 45
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 45
Branch analysis from position: 28
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 45
Branch analysis from position: 41
Branch analysis from position: 45
Branch analysis from position: 46
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 46
filename:       /in/qlaZL
function name:  (null)
number of ops:  51
compiled vars:  !0 = $array, !1 = $result, !2 = $name, !3 = $value, !4 = $parts, !5 = $parentKey, !6 = $childKey, !7 = $grandchildKey
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   41     1        ASSIGN                                                   !1, <array>
   42     2      > FE_RESET_R                                       $10     !0, ->46
          3    > > FE_FETCH_R                                               $10, $11, ->46
          4    >   FETCH_LIST_R                                     $12     $11, 'name'
          5        ASSIGN                                                   !2, $12
          6        FETCH_LIST_R                                     $14     $11, 'value'
          7        ASSIGN                                                   !3, $14
          8        FREE                                                     $11
   43     9        INIT_FCALL                                               'explode'
         10        SEND_VAL                                                 '.'
         11        SEND_VAR                                                 !2
         12        DO_ICALL                                         $16     
         13        ASSIGN                                                   !4, $16
   44    14        FETCH_DIM_R                                      ~18     !4, 0
         15        CONCAT                                           ~19     ~18, 's'
         16        ASSIGN                                                   !5, ~19
   45    17        INIT_FCALL                                               'implode'
         18        INIT_FCALL                                               'array_splice'
         19        SEND_REF                                                 !4
         20        SEND_VAL                                                 0
         21        INIT_FCALL                                               'ctype_digit'
         22        FETCH_DIM_R                                      ~21     !4, 1
         23        SEND_VAL                                                 ~21
         24        DO_ICALL                                         $22     
         25      > JMPZ                                                     $22, ->28
         26    >   QM_ASSIGN                                        ~23     2
         27      > JMP                                                      ->29
         28    >   QM_ASSIGN                                        ~23     1
         29    >   SEND_VAL                                                 ~23
         30        DO_ICALL                                         $24     
         31        SEND_VAR                                                 $24
         32        DO_ICALL                                         $25     
         33        ASSIGN                                                   !6, $25
   46    34        INIT_FCALL                                               'implode'
         35        SEND_VAL                                                 '.'
         36        SEND_VAR                                                 !4
         37        DO_ICALL                                         $27     
         38        ASSIGN                                                   !7, $27
   47    39        IS_NOT_IDENTICAL                                         !7, 'name'
         40      > JMPZ                                                     ~29, ->45
   48    41    >   FETCH_DIM_W                                      $30     !1, !5
         42        FETCH_DIM_W                                      $31     $30, !6
         43        ASSIGN_DIM                                               $31, !7
         44        OP_DATA                                                  !3
   42    45    > > JMP                                                      ->3
         46    >   FE_FREE                                                  $10
   51    47        INIT_FCALL                                               'var_export'
         48        SEND_VAR                                                 !1
         49        DO_ICALL                                                 
         50      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
146.36 ms | 1011 KiB | 18 Q