3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = [ [ "id" => "127", "title" => "Apple", "deleted" => "0", "parent" => NULL, "usp_id" => "445", "user_id" => NULL, ], [ "id" => "159", "title" => "Renault Duster", "deleted" => "0", "parent" => NULL, "usp_id" => "495", "user_id" => NULL, ], [ "id" => "7", "title" => "Services", "deleted" => "0", "parent" => "127", "usp_id" => "79", "user_id" => "275", ], ]; foreach ($arr as $key0 => $record) { if (null !== $record['parent']) { foreach ($arr as $key1 => $parent) { if ($parent['id'] === $record['parent']) { $arr[$key1]['children'][] = $record; // push child into parent['sub'] unset($arr[$key0]); // delete child } } } } print_r($arr);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 22
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 22
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 21
Branch analysis from position: 7
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 20
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 20
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 19
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 19
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 20
Branch analysis from position: 21
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
filename:       /in/13NcN
function name:  (null)
number of ops:  27
compiled vars:  !0 = $arr, !1 = $record, !2 = $key0, !3 = $parent, !4 = $key1
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   30     1      > FE_RESET_R                                       $6      !0, ->22
          2    > > FE_FETCH_R                                       ~7      $6, !1, ->22
          3    >   ASSIGN                                                   !2, ~7
   31     4        FETCH_DIM_R                                      ~9      !1, 'parent'
          5        TYPE_CHECK                                  1020          ~9
          6      > JMPZ                                                     ~10, ->21
   32     7    > > FE_RESET_R                                       $11     !0, ->20
          8    > > FE_FETCH_R                                       ~12     $11, !3, ->20
          9    >   ASSIGN                                                   !4, ~12
   33    10        FETCH_DIM_R                                      ~14     !3, 'id'
         11        FETCH_DIM_R                                      ~15     !1, 'parent'
         12        IS_IDENTICAL                                             ~14, ~15
         13      > JMPZ                                                     ~16, ->19
   34    14    >   FETCH_DIM_W                                      $17     !0, !4
         15        FETCH_DIM_W                                      $18     $17, 'children'
         16        ASSIGN_DIM                                               $18
         17        OP_DATA                                                  !1
   35    18        UNSET_DIM                                                !0, !2
   32    19    > > JMP                                                      ->8
         20    >   FE_FREE                                                  $11
   30    21    > > JMP                                                      ->2
         22    >   FE_FREE                                                  $6
   41    23        INIT_FCALL                                               'print_r'
         24        SEND_VAR                                                 !0
         25        DO_ICALL                                                 
         26      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
146.47 ms | 1001 KiB | 14 Q