3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = array(); $arr[] = array('p' => 3, 'id' => 4); $arr[] = array('p' => 3, 'id' => 5); $arr[] = array('p' => 3, 'id' => 6); $arr[] = array('p' => 2, 'id' => 3); $arr[] = array('p' => 1, 'id' => 2); $arr[] = array('p' => 1, 'id' => 7); $arr[] = array('p' => 0, 'id' => 1); $mas = array(); foreach($arr as $ind => $itm) { if(isset($mas[$itm['id']])) { if($itm['p'] == 0) { $mas[$itm['id']]['elements'] = $mas[$itm['id']]; $mas[$itm['id']]['name'] = 'aaa'.$ind; }else{ $mas[$itm['p']][$itm['id']]['elements'] = $mas[$itm['id']]; unset($mas[$itm['id']]); $mas[$itm['p']][$itm['id']]['name'] = 'aaa'.$ind; } } } print_r($mas);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 17, Position 2 = 55
Branch analysis from position: 17
2 jumps found. (Code = 78) Position 1 = 18, Position 2 = 55
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 54
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 37
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 54
Branch analysis from position: 54
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
Branch analysis from position: 37
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
Branch analysis from position: 54
Branch analysis from position: 55
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 55
filename:       /in/TLKeR
function name:  (null)
number of ops:  60
compiled vars:  !0 = $arr, !1 = $mas, !2 = $itm, !3 = $ind
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
    3     1        ASSIGN_DIM                                               !0
          2        OP_DATA                                                  <array>
    4     3        ASSIGN_DIM                                               !0
          4        OP_DATA                                                  <array>
    5     5        ASSIGN_DIM                                               !0
          6        OP_DATA                                                  <array>
    6     7        ASSIGN_DIM                                               !0
          8        OP_DATA                                                  <array>
    7     9        ASSIGN_DIM                                               !0
         10        OP_DATA                                                  <array>
    8    11        ASSIGN_DIM                                               !0
         12        OP_DATA                                                  <array>
    9    13        ASSIGN_DIM                                               !0
         14        OP_DATA                                                  <array>
   11    15        ASSIGN                                                   !1, <array>
   12    16      > FE_RESET_R                                       $13     !0, ->55
         17    > > FE_FETCH_R                                       ~14     $13, !2, ->55
         18    >   ASSIGN                                                   !3, ~14
   14    19        FETCH_DIM_R                                      ~16     !2, 'id'
         20        ISSET_ISEMPTY_DIM_OBJ                         0          !1, ~16
         21      > JMPZ                                                     ~17, ->54
   16    22    >   FETCH_DIM_R                                      ~18     !2, 'p'
         23        IS_EQUAL                                                 ~18, 0
         24      > JMPZ                                                     ~19, ->37
   18    25    >   FETCH_DIM_R                                      ~20     !2, 'id'
         26        FETCH_DIM_R                                      ~23     !2, 'id'
         27        FETCH_DIM_R                                      ~24     !1, ~23
         28        FETCH_DIM_W                                      $21     !1, ~20
         29        ASSIGN_DIM                                               $21, 'elements'
         30        OP_DATA                                                  ~24
   19    31        FETCH_DIM_R                                      ~25     !2, 'id'
         32        CONCAT                                           ~28     'aaa', !3
         33        FETCH_DIM_W                                      $26     !1, ~25
         34        ASSIGN_DIM                                               $26, 'name'
         35        OP_DATA                                                  ~28
         36      > JMP                                                      ->54
   22    37    >   FETCH_DIM_R                                      ~29     !2, 'p'
         38        FETCH_DIM_R                                      ~31     !2, 'id'
         39        FETCH_DIM_R                                      ~34     !2, 'id'
         40        FETCH_DIM_R                                      ~35     !1, ~34
         41        FETCH_DIM_W                                      $30     !1, ~29
         42        FETCH_DIM_W                                      $32     $30, ~31
         43        ASSIGN_DIM                                               $32, 'elements'
         44        OP_DATA                                                  ~35
   23    45        FETCH_DIM_R                                      ~36     !2, 'id'
         46        UNSET_DIM                                                !1, ~36
   24    47        FETCH_DIM_R                                      ~37     !2, 'p'
         48        FETCH_DIM_R                                      ~39     !2, 'id'
         49        CONCAT                                           ~42     'aaa', !3
         50        FETCH_DIM_W                                      $38     !1, ~37
         51        FETCH_DIM_W                                      $40     $38, ~39
         52        ASSIGN_DIM                                               $40, 'name'
         53        OP_DATA                                                  ~42
   12    54    > > JMP                                                      ->17
         55    >   FE_FREE                                                  $13
   33    56        INIT_FCALL                                               'print_r'
         57        SEND_VAR                                                 !1
         58        DO_ICALL                                                 
         59      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.04 ms | 1405 KiB | 15 Q