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; } } 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]); } echo var_export($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 = 59, Position 2 = 92
Branch analysis from position: 59
2 jumps found. (Code = 78) Position 1 = 60, Position 2 = 92
Branch analysis from position: 60
1 jumps found. (Code = 42) Position 1 = 80
Branch analysis from position: 80
2 jumps found. (Code = 44) Position 1 = 85, Position 2 = 72
Branch analysis from position: 85
1 jumps found. (Code = 42) Position 1 = 59
Branch analysis from position: 59
Branch analysis from position: 72
2 jumps found. (Code = 43) Position 1 = 75, Position 2 = 78
Branch analysis from position: 75
1 jumps found. (Code = 42) Position 1 = 80
Branch analysis from position: 80
Branch analysis from position: 78
2 jumps found. (Code = 44) Position 1 = 85, Position 2 = 72
Branch analysis from position: 85
Branch analysis from position: 72
Branch analysis from position: 92
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 92
Branch analysis from position: 57
filename:       /in/5RUJO
function name:  (null)
number of ops:  98
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
   30    58      > FE_RESET_R                                       $40     !1, ->92
         59    > > FE_FETCH_R                                       ~41     $40, !10, ->92
         60    >   ASSIGN                                                   !11, ~41
   31    61        INIT_FCALL                                               'explode'
         62        SEND_VAL                                                 '.'
         63        SEND_VAR                                                 !11
         64        DO_ICALL                                         $43     
         65        ASSIGN                                                   !12, $43
   32    66        INIT_FCALL                                               'array_shift'
         67        SEND_REF                                                 !12
         68        DO_ICALL                                         $45     
         69        ASSIGN                                                   !13, $45
   33    70        ASSIGN                                                   !14, <array>
   34    71      > JMP                                                      ->80
   35    72    >   COUNT                                            ~48     !14
         73        IS_IDENTICAL                                             ~48, 0
         74      > JMPZ                                                     ~49, ->78
   36    75    >   ASSIGN_DIM                                               !14, !6
         76        OP_DATA                                                  !10
         77      > JMP                                                      ->80
   38    78    >   INIT_ARRAY                                       ~51     !14, !6
         79        ASSIGN                                                   !14, ~51
   34    80    >   INIT_FCALL                                               'array_pop'
         81        SEND_REF                                                 !12
         82        DO_ICALL                                         $53     
         83        ASSIGN                                           ~54     !6, $53
         84      > JMPNZ                                                    ~54, ->72
   41    85    >   INIT_FCALL                                               'array_merge_recursive'
         86        SEND_VAR                                                 !1
         87        SEND_VAR                                                 !14
         88        DO_ICALL                                         $55     
         89        ASSIGN                                                   !1, $55
   42    90        UNSET_DIM                                                !1, !11
   30    91      > JMP                                                      ->59
         92    >   FE_FREE                                                  $40
   45    93        INIT_FCALL                                               'var_export'
         94        SEND_VAR                                                 !1
         95        DO_ICALL                                         $57     
         96        ECHO                                                     $57
         97      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
176.14 ms | 1409 KiB | 31 Q