3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ [ 'parent' => 'Basic', 'parentId' => 1, 'child' => 'Birthday', 'childId' => 2, ], [ 'parent' => 'Basic', 'parentId' => 1, 'child' => 'Gender', 'childId' => 3, ], [ 'parent' => 'Geo', 'parentId' => 10, 'child' => 'Current City', 'childId' => 11, ], [ 'parent' => 'Known me', 'parentId' => 5, 'child' => 'My personality', 'childId' => 7, ], [ 'parent' => 'Known me', 'parentId' => 5, 'child' => 'Best life moment', 'childId' => 8, ], ]; $result = []; foreach ($array as $row) { if (!isset($result[$row['parentId']])) { unset($row['childId']); $row['child'] = (array) $row['child']; $result[$row['parentId']] = $row; } else { $result[$row['parentId']]['child'][] = $row['child']; } } var_export(array_values($result));
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 24
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 24
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 17
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
filename:       /in/BBZ2N
function name:  (null)
number of ops:  32
compiled vars:  !0 = $array, !1 = $result, !2 = $row
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   36     1        ASSIGN                                                   !1, <array>
   37     2      > FE_RESET_R                                       $5      !0, ->24
          3    > > FE_FETCH_R                                               $5, !2, ->24
   38     4    >   FETCH_DIM_R                                      ~6      !2, 'parentId'
          5        ISSET_ISEMPTY_DIM_OBJ                         0  ~7      !1, ~6
          6        BOOL_NOT                                         ~8      ~7
          7      > JMPZ                                                     ~8, ->17
   39     8    >   UNSET_DIM                                                !2, 'childId'
   40     9        FETCH_DIM_R                                      ~10     !2, 'child'
         10        CAST                                          7  ~11     ~10
         11        ASSIGN_DIM                                               !2, 'child'
         12        OP_DATA                                                  ~11
   41    13        FETCH_DIM_R                                      ~12     !2, 'parentId'
         14        ASSIGN_DIM                                               !1, ~12
         15        OP_DATA                                                  !2
   38    16      > JMP                                                      ->23
   43    17    >   FETCH_DIM_R                                      ~14     !2, 'parentId'
         18        FETCH_DIM_R                                      ~18     !2, 'child'
         19        FETCH_DIM_W                                      $15     !1, ~14
         20        FETCH_DIM_W                                      $16     $15, 'child'
         21        ASSIGN_DIM                                               $16
         22        OP_DATA                                                  ~18
   37    23    > > JMP                                                      ->3
         24    >   FE_FREE                                                  $5
   46    25        INIT_FCALL                                               'var_export'
         26        INIT_FCALL                                               'array_values'
         27        SEND_VAR                                                 !1
         28        DO_ICALL                                         $19     
         29        SEND_VAR                                                 $19
         30        DO_ICALL                                                 
         31      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
136.57 ms | 1000 KiB | 15 Q