3v4l.org

run code in 300+ PHP versions simultaneously
<?php $input = [ 'a.b.c.d = 1', 'a.b.c.e = Joey', 'a.b.c.f = Smith', 'a.b.g.d = 2', 'a.b.g.e = Chris', 'a.b.g.f = Divner' ]; $data = []; $cleanKeys = []; foreach($input as $record) { $equals = strrpos($record, '='); $value = trim(substr($record, $equals+1)); $key = trim(substr($record, 0, $equals)); $lastDot = strrpos($key, '.'); $appKey = substr($key, $lastDot+1); $curKey = substr($key, 0, $lastDot); $data[$curKey][$appKey] = $value; if (strpos($curKey, '.') !== FALSE) { $cleanKeys[] = $curKey; } } var_dump($data); foreach($data as $k => $v){ $keys = explode('.', $k); $firstKey = array_shift($keys); $newData = []; while($key = array_pop($keys)) { if (count($newData) === 0) { $newData[$key] = $v; } else { $newData = [$key => $newData]; } } $data = array_merge_recursive($data, $newData); unset($data[$k]); } var_dump($data);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 57
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 57
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 54, Position 2 = 56
Branch analysis from position: 54
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 56
Branch analysis from position: 57
2 jumps found. (Code = 77) Position 1 = 62, Position 2 = 95
Branch analysis from position: 62
2 jumps found. (Code = 78) Position 1 = 63, Position 2 = 95
Branch analysis from position: 63
1 jumps found. (Code = 42) Position 1 = 83
Branch analysis from position: 83
2 jumps found. (Code = 44) Position 1 = 88, Position 2 = 75
Branch analysis from position: 88
1 jumps found. (Code = 42) Position 1 = 62
Branch analysis from position: 62
Branch analysis from position: 75
2 jumps found. (Code = 43) Position 1 = 78, Position 2 = 81
Branch analysis from position: 78
1 jumps found. (Code = 42) Position 1 = 83
Branch analysis from position: 83
Branch analysis from position: 81
2 jumps found. (Code = 44) Position 1 = 88, Position 2 = 75
Branch analysis from position: 88
Branch analysis from position: 75
Branch analysis from position: 95
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 95
Branch analysis from position: 57
filename:       /in/lWECX
function name:  (null)
number of ops:  100
compiled vars:  !0 = $input, !1 = $data, !2 = $cleanKeys, !3 = $record, !4 = $equals, !5 = $value, !6 = $key, !7 = $lastDot, !8 = $appKey, !9 = $curKey, !10 = $v, !11 = $k, !12 = $keys, !13 = $firstKey, !14 = $newData
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   13     1        ASSIGN                                                   !1, <array>
   14     2        ASSIGN                                                   !2, <array>
   15     3      > FE_RESET_R                                       $18     !0, ->57
          4    > > FE_FETCH_R                                               $18, !3, ->57
   16     5    >   INIT_FCALL                                               'strrpos'
          6        SEND_VAR                                                 !3
          7        SEND_VAL                                                 '%3D'
          8        DO_ICALL                                         $19     
          9        ASSIGN                                                   !4, $19
   17    10        INIT_FCALL                                               'trim'
         11        INIT_FCALL                                               'substr'
         12        SEND_VAR                                                 !3
         13        ADD                                              ~21     !4, 1
         14        SEND_VAL                                                 ~21
         15        DO_ICALL                                         $22     
         16        SEND_VAR                                                 $22
         17        DO_ICALL                                         $23     
         18        ASSIGN                                                   !5, $23
   18    19        INIT_FCALL                                               'trim'
         20        INIT_FCALL                                               'substr'
         21        SEND_VAR                                                 !3
         22        SEND_VAL                                                 0
         23        SEND_VAR                                                 !4
         24        DO_ICALL                                         $25     
         25        SEND_VAR                                                 $25
         26        DO_ICALL                                         $26     
         27        ASSIGN                                                   !6, $26
   20    28        INIT_FCALL                                               'strrpos'
         29        SEND_VAR                                                 !6
         30        SEND_VAL                                                 '.'
         31        DO_ICALL                                         $28     
         32        ASSIGN                                                   !7, $28
   21    33        INIT_FCALL                                               'substr'
         34        SEND_VAR                                                 !6
         35        ADD                                              ~30     !7, 1
         36        SEND_VAL                                                 ~30
         37        DO_ICALL                                         $31     
         38        ASSIGN                                                   !8, $31
   22    39        INIT_FCALL                                               'substr'
         40        SEND_VAR                                                 !6
         41        SEND_VAL                                                 0
         42        SEND_VAR                                                 !7
         43        DO_ICALL                                         $33     
         44        ASSIGN                                                   !9, $33
   23    45        FETCH_DIM_W                                      $35     !1, !9
         46        ASSIGN_DIM                                               $35, !8
         47        OP_DATA                                                  !5
   25    48        INIT_FCALL                                               'strpos'
         49        SEND_VAR                                                 !9
         50        SEND_VAL                                                 '.'
         51        DO_ICALL                                         $37     
         52        TYPE_CHECK                                  1018          $37
         53      > JMPZ                                                     ~38, ->56
   26    54    >   ASSIGN_DIM                                               !2
         55        OP_DATA                                                  !9
   15    56    > > JMP                                                      ->4
         57    >   FE_FREE                                                  $18
   31    58        INIT_FCALL                                               'var_dump'
         59        SEND_VAR                                                 !1
         60        DO_ICALL                                                 
   34    61      > FE_RESET_R                                       $41     !1, ->95
         62    > > FE_FETCH_R                                       ~42     $41, !10, ->95
         63    >   ASSIGN                                                   !11, ~42
   35    64        INIT_FCALL                                               'explode'
         65        SEND_VAL                                                 '.'
         66        SEND_VAR                                                 !11
         67        DO_ICALL                                         $44     
         68        ASSIGN                                                   !12, $44
   36    69        INIT_FCALL                                               'array_shift'
         70        SEND_REF                                                 !12
         71        DO_ICALL                                         $46     
         72        ASSIGN                                                   !13, $46
   37    73        ASSIGN                                                   !14, <array>
   38    74      > JMP                                                      ->83
   39    75    >   COUNT                                            ~49     !14
         76        IS_IDENTICAL                                             ~49, 0
         77      > JMPZ                                                     ~50, ->81
   40    78    >   ASSIGN_DIM                                               !14, !6
         79        OP_DATA                                                  !10
         80      > JMP                                                      ->83
   42    81    >   INIT_ARRAY                                       ~52     !14, !6
         82        ASSIGN                                                   !14, ~52
   38    83    >   INIT_FCALL                                               'array_pop'
         84        SEND_REF                                                 !12
         85        DO_ICALL                                         $54     
         86        ASSIGN                                           ~55     !6, $54
         87      > JMPNZ                                                    ~55, ->75
   45    88    >   INIT_FCALL                                               'array_merge_recursive'
         89        SEND_VAR                                                 !1
         90        SEND_VAR                                                 !14
         91        DO_ICALL                                         $56     
         92        ASSIGN                                                   !1, $56
   46    93        UNSET_DIM                                                !1, !11
   34    94      > JMP                                                      ->62
         95    >   FE_FREE                                                  $41
   48    96        INIT_FCALL                                               'var_dump'
         97        SEND_VAR                                                 !1
         98        DO_ICALL                                                 
         99      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.69 ms | 1404 KiB | 31 Q