3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $input = array( array('id' => 2, 'name' => 'Clement', 'upper' => 0), array('id' => 1, 'name' => 'Jean', 'upper' => 1), array('id' => 1, 'name' => 'Annie', 'upper' => 1) ); $map = array(); foreach ($input as $node) { // init self if (!array_key_exists($node['sn'], $map)) { $map[$node['sn']] = array('self' => $node['name']); } else { $map[$node['sn']]['self'] = $node['name']; } // init parent if (!array_key_exists($node['upper'], $map)) { $map[$node['upper']] = array(); } // add to parent $map[$node['upper']][$node['sn']] = & $map[$node['sn']]; } print_r($map[0]);
based on uuUTM
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = 3, Position 2 = 40
Branch analysis from position: 3
Jump found. Position 1 = 4, Position 2 = 40
Branch analysis from position: 4
Jump found. Position 1 = 11, Position 2 = 17
Branch analysis from position: 11
Jump found. Position 1 = 22
Branch analysis from position: 22
Jump found. Position 1 = 29, Position 2 = 32
Branch analysis from position: 29
Jump found. Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 32
Branch analysis from position: 17
Jump found. Position 1 = 29, Position 2 = 32
Branch analysis from position: 29
Branch analysis from position: 32
Branch analysis from position: 40
Jump found. Position 1 = -2
Branch analysis from position: 40
filename:       /in/LJN4H
function name:  (null)
number of ops:  46
compiled vars:  !0 = $input, !1 = $map, !2 = $node
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   3     0  E >   ASSIGN                                                   !0, <array>
   8     1        ASSIGN                                                   !1, <array>
  10     2      > FE_RESET_R                                       $5      !0, ->40
         3    > > FE_FETCH_R                                               $5, !2, ->40
  12     4    >   INIT_FCALL                                               'array_key_exists'
         5        FETCH_DIM_R                                      $6      !2, 'sn'
         6        SEND_VAR                                                 $6
         7        SEND_VAR                                                 !1
         8        DO_ICALL                                         $7      
         9        BOOL_NOT                                         ~8      $7
        10      > JMPZ                                                     ~8, ->17
  13    11    >   FETCH_DIM_R                                      $9      !2, 'sn'
        12        FETCH_DIM_R                                      $11     !2, 'name'
        13        INIT_ARRAY                                       ~12     $11, 'self'
        14        ASSIGN_DIM                                               !1, $9
        15        OP_DATA                                                  ~12
        16      > JMP                                                      ->22
  16    17    >   FETCH_DIM_R                                      $13     !2, 'sn'
        18        FETCH_DIM_R                                      $16     !2, 'name'
        19        FETCH_DIM_W                                      $14     !1, $13
        20        ASSIGN_DIM                                               $14, 'self'
        21        OP_DATA                                                  $16
  20    22    >   INIT_FCALL                                               'array_key_exists'
        23        FETCH_DIM_R                                      $17     !2, 'upper'
        24        SEND_VAR                                                 $17
        25        SEND_VAR                                                 !1
        26        DO_ICALL                                         $18     
        27        BOOL_NOT                                         ~19     $18
        28      > JMPZ                                                     ~19, ->32
  21    29    >   FETCH_DIM_R                                      $20     !2, 'upper'
        30        ASSIGN_DIM                                               !1, $20
        31        OP_DATA                                                  <array>
  25    32    >   FETCH_DIM_R                                      $22     !2, 'upper'
        33        FETCH_DIM_R                                      $24     !2, 'sn'
        34        FETCH_DIM_W                                      $23     !1, $22
        35        FETCH_DIM_W                                      $25     $23, $24
        36        FETCH_DIM_R                                      $26     !2, 'sn'
        37        FETCH_DIM_W                                      $27     !1, $26
        38        ASSIGN_REF                                               $25, $27
        39      > JMP                                                      ->3
        40    >   FE_FREE                                                  $5
  28    41        INIT_FCALL                                               'print_r'
        42        FETCH_DIM_R                                      $29     !1, 0
        43        SEND_VAR                                                 $29
        44        DO_ICALL                                                 
        45      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 7.3.0