3v4l.org

run code in 300+ PHP versions simultaneously
<?php $locations = [ ['country'=>'USA', 'state'=>'New York', 'city'=>'NYC', 'location'=>'Central Park', 'street'=>'7th Ave', 'count'=>123], ['country'=>'USA', 'state'=>'Maryland', 'city'=>'Baltimore', 'location'=>'Harber', 'count'=>24], ['country'=>'USA', 'state'=>'Michigan', 'city'=>'Lansing', 'location'=>'Midtown', 'building'=>'H2B', 'count'=>7], ['country'=>'France', 'state'=>'Sud', 'city'=>'Marseille', 'location'=>'Centre Ville', 'count'=>12], ]; $hierarchy = array(); $levels = array_reverse( array('country', 'state', 'city', 'location') ); $lastLevel = 'count'; foreach ( $locations as $L ) { $array = $L[$lastLevel]; foreach ( $levels as $level ) { $array = array($L[$level] => $array); } $hierarchy = array_merge_recursive($hierarchy, $array); } print_r($hierarchy);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 24
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 24
Branch analysis from position: 9
2 jumps found. (Code = 77) Position 1 = 12, Position 2 = 17
Branch analysis from position: 12
2 jumps found. (Code = 78) Position 1 = 13, Position 2 = 17
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 17
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
filename:       /in/n7vYW
function name:  (null)
number of ops:  29
compiled vars:  !0 = $locations, !1 = $hierarchy, !2 = $levels, !3 = $lastLevel, !4 = $L, !5 = $array, !6 = $level
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
    9     1        ASSIGN                                                   !1, <array>
   11     2        INIT_FCALL                                               'array_reverse'
   12     3        SEND_VAL                                                 <array>
   11     4        DO_ICALL                                         $9      
          5        ASSIGN                                                   !2, $9
   15     6        ASSIGN                                                   !3, 'count'
   18     7      > FE_RESET_R                                       $12     !0, ->24
          8    > > FE_FETCH_R                                               $12, !4, ->24
   20     9    >   FETCH_DIM_R                                      ~13     !4, !3
         10        ASSIGN                                                   !5, ~13
   22    11      > FE_RESET_R                                       $15     !2, ->17
         12    > > FE_FETCH_R                                               $15, !6, ->17
   24    13    >   FETCH_DIM_R                                      ~16     !4, !6
         14        INIT_ARRAY                                       ~17     !5, ~16
         15        ASSIGN                                                   !5, ~17
   22    16      > JMP                                                      ->12
         17    >   FE_FREE                                                  $15
   27    18        INIT_FCALL                                               'array_merge_recursive'
         19        SEND_VAR                                                 !1
         20        SEND_VAR                                                 !5
         21        DO_ICALL                                         $19     
         22        ASSIGN                                                   !1, $19
   18    23      > JMP                                                      ->8
         24    >   FE_FREE                                                  $12
   30    25        INIT_FCALL                                               'print_r'
         26        SEND_VAR                                                 !1
         27        DO_ICALL                                                 
         28      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
140.76 ms | 1440 KiB | 16 Q