3v4l.org

run code in 300+ PHP versions simultaneously
<?php $rows = [ ['name' => 'blah', 'path' => 'A'], ['name' => 'blah1', 'path' => 'AA'], ['name' => 'blah', 'path' => 'AB'], ['name' => 'blah', 'path' => 'C'], ['name' => 'blah', 'path' => 'D'], ['name' => 'blah2', 'path' => 'AA'], ['name' => 'blah', 'path' => 'B'], ['name' => 'blah', 'path' => 'BA'], ['name' => 'blah', 'path' => 'BAA'], ['name' => 'blah', 'path' => 'CA'], ]; $copy = $rows; uasort($rows, fn($a, $b) => $b['path'] <=> $a['path']); foreach ($rows as $i => $row1) { foreach ($rows as $j => &$row2) { if (substr($row1['path'], 0, -1) === $row2['path']) { $copy[$j]['children'][] = $row1; unset($copy[$i]); } } } var_export($copy);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 30
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 30
Branch analysis from position: 9
2 jumps found. (Code = 125) Position 1 = 11, Position 2 = 28
Branch analysis from position: 11
2 jumps found. (Code = 126) Position 1 = 12, Position 2 = 28
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 27
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 27
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 28
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
filename:       /in/ctjlD
function name:  (null)
number of ops:  35
compiled vars:  !0 = $rows, !1 = $copy, !2 = $row1, !3 = $i, !4 = $row2, !5 = $j
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   16     1        ASSIGN                                                   !1, !0
   17     2        INIT_FCALL                                               'uasort'
          3        SEND_REF                                                 !0
          4        DECLARE_LAMBDA_FUNCTION                          ~8      [0]
          5        SEND_VAL                                                 ~8
          6        DO_ICALL                                                 
   18     7      > FE_RESET_R                                       $10     !0, ->30
          8    > > FE_FETCH_R                                       ~11     $10, !2, ->30
          9    >   ASSIGN                                                   !3, ~11
   19    10      > FE_RESET_RW                                      $13     !0, ->28
         11    > > FE_FETCH_RW                                      ~14     $13, !4, ->28
         12    >   ASSIGN                                                   !5, ~14
   20    13        INIT_FCALL                                               'substr'
         14        FETCH_DIM_R                                      ~16     !2, 'path'
         15        SEND_VAL                                                 ~16
         16        SEND_VAL                                                 0
         17        SEND_VAL                                                 -1
         18        DO_ICALL                                         $17     
         19        FETCH_DIM_R                                      ~18     !4, 'path'
         20        IS_IDENTICAL                                             $17, ~18
         21      > JMPZ                                                     ~19, ->27
   21    22    >   FETCH_DIM_W                                      $20     !1, !5
         23        FETCH_DIM_W                                      $21     $20, 'children'
         24        ASSIGN_DIM                                               $21
         25        OP_DATA                                                  !2
   22    26        UNSET_DIM                                                !1, !3
   19    27    > > JMP                                                      ->11
         28    >   FE_FREE                                                  $13
   18    29      > JMP                                                      ->8
         30    >   FE_FREE                                                  $10
   27    31        INIT_FCALL                                               'var_export'
         32        SEND_VAR                                                 !1
         33        DO_ICALL                                                 
         34      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ctjlD
function name:  {closure}
number of ops:  7
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        FETCH_DIM_R                                      ~2      !1, 'path'
          3        FETCH_DIM_R                                      ~3      !0, 'path'
          4        SPACESHIP                                        ~4      ~2, ~3
          5      > RETURN                                                   ~4
          6*     > RETURN                                                   null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.54 ms | 1012 KiB | 16 Q