3v4l.org

run code in 500+ PHP versions simultaneously
<?php $list = [ [ 'name' => 'blah', 'path' => 'A' ], [ 'name' => 'blah', 'path' => 'AA' ], [ 'name' => 'blah', 'path' => 'AB' ], [ 'name' => 'blah', 'path' => 'B' ], [ 'name' => 'blah', 'path' => 'BA' ], [ 'name' => 'blah', 'path' => 'BAA' ], ]; $result = array_reduce($list, function ($a, $c) { $l = substr($c['path'], 0, 1); isset($a[$l]) ? $a[$l]['children'][] = $c : $a[$l] = [ 'name' => $c['name'], 'path' => $c['path'], 'children' => [] ]; return $a; }, []); // to remove the letter keys, uncomment the next line // $result = array_values($result); var_export($result);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/fWsdc
function name:  (null)
number of ops:  12
compiled vars:  !0 = $list, !1 = $result
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
   30     1        INIT_FCALL                                                   'array_reduce'
          2        SEND_VAR                                                     !0
          3        DECLARE_LAMBDA_FUNCTION                              ~3      [0]
   40     4        SEND_VAL                                                     ~3
          5        SEND_VAL                                                     <array>
   30     6        DO_ICALL                                             $4      
          7        ASSIGN                                                       !1, $4
   46     8        INIT_FCALL                                                   'var_export'
          9        SEND_VAR                                                     !1
         10        DO_ICALL                                                     
         11      > RETURN                                                       1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 14
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/fWsdc
function name:  {closure:/in/fWsdc:30}
number of ops:  25
compiled vars:  !0 = $a, !1 = $c, !2 = $l
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   30     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   31     2        FETCH_DIM_R                                          ~3      !1, 'path'
          3        FRAMELESS_ICALL_3                substr              ~4      ~3, 0
          4        OP_DATA                                                      1
          5        ASSIGN                                                       !2, ~4
   32     6        ISSET_ISEMPTY_DIM_OBJ                             0          !0, !2
          7      > JMPZ                                                         ~6, ->14
   33     8    >   FETCH_DIM_W                                          $7      !0, !2
          9        FETCH_DIM_W                                          $8      $7, 'children'
         10        ASSIGN_DIM                                           ~9      $8
         11        OP_DATA                                                      !1
         12        QM_ASSIGN                                            ~10     ~9
         13      > JMP                                                          ->22
   35    14    >   FETCH_DIM_R                                          ~12     !1, 'name'
         15        INIT_ARRAY                                           ~13     ~12, 'name'
   36    16        FETCH_DIM_R                                          ~14     !1, 'path'
         17        ADD_ARRAY_ELEMENT                                    ~13     ~14, 'path'
   35    18        ADD_ARRAY_ELEMENT                                    ~13     <array>, 'children'
   34    19        ASSIGN_DIM                                           ~11     !0, !2
   35    20        OP_DATA                                                      ~13
         21        QM_ASSIGN                                            ~10     ~11
         22    >   FREE                                                         ~10
   39    23      > RETURN                                                       !0
   40    24*     > RETURN                                                       null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
159.67 ms | 1540 KiB | 15 Q