3v4l.org

run code in 500+ PHP versions simultaneously
<?php $originalArray = array( array('id' => 1, 'sub-id' => 0), array('id' => 2, 'sub-id' => 0), array('id' => 3, 'sub-id' => 1), array('id' => 4, 'sub-id' => 3), array('id' => 5, 'sub-id' => 4), array('id' => 6, 'sub-id' => 0), array('id' => 7, 'sub-id' => 0), array('id' => 8, 'sub-id' => 6), array('id' => 9, 'sub-id' => 8), array('id' => 10, 'sub-id' => 8) ); $input = array(); foreach ($originalArray as $el) { $input[ $el['id'] ] = (object)($el + array('sub' => array())); } $result = array(); foreach ($input as $el) { $sid = $el->{'sub-id'}; if ( !$sid ) { $result[] = $el; } else { $input[$sid]->sub[] = $el; } } print_r($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 10
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 10
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 10
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 26
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 26
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 21
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
Branch analysis from position: 10
filename:       /in/8VMJr
function name:  (null)
number of ops:  31
compiled vars:  !0 = $originalArray, !1 = $input, !2 = $el, !3 = $result, !4 = $sid
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
   16     1        ASSIGN                                                       !1, <array>
   17     2      > FE_RESET_R                                           $7      !0, ->10
          3    > > FE_FETCH_R                                                   $7, !2, ->10
   18     4    >   FETCH_DIM_R                                          ~8      !2, 'id'
          5        ADD                                                  ~10     !2, <array>
          6        CAST                                              8  ~11     ~10
          7        ASSIGN_DIM                                                   !1, ~8
          8        OP_DATA                                                      ~11
   17     9      > JMP                                                          ->3
         10    >   FE_FREE                                                      $7
   21    11        ASSIGN                                                       !3, <array>
   22    12      > FE_RESET_R                                           $13     !1, ->26
         13    > > FE_FETCH_R                                                   $13, !2, ->26
   23    14    >   FETCH_OBJ_R                                          ~14     !2, 'sub-id'
         15        ASSIGN                                                       !4, ~14
   24    16        BOOL_NOT                                             ~16     !4
         17      > JMPZ                                                         ~16, ->21
   25    18    >   ASSIGN_DIM                                                   !3
         19        OP_DATA                                                      !2
   24    20      > JMP                                                          ->25
   28    21    >   FETCH_DIM_W                                          $18     !1, !4
         22        FETCH_OBJ_W                                          $19     $18, 'sub'
         23        ASSIGN_DIM                                                   $19
         24        OP_DATA                                                      !2
   22    25    > > JMP                                                          ->13
         26    >   FE_FREE                                                      $13
   32    27        INIT_FCALL                                                   'print_r'
         28        SEND_VAR                                                     !3
         29        DO_ICALL                                                     
         30      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
174.19 ms | 3926 KiB | 14 Q