3v4l.org

run code in 300+ PHP versions simultaneously
<?php $directory = array ( '0' => (object) array ( 'dir_name' => 'Car', 'dir_id' => 'car' ), '1' => (object) array ( 'dir_name' => 'Bus', 'dir_id' => 'bus' ), '2' => (object) array ( 'dir_name' => 'Truck', 'dir_id' => 'truck' ) ); $subdirectory = array ( '0' =>(object) array ( 'sub_name' => 'Toyota', 'sub_id' => 'toyota', 'dir_id' => 'car' ), '1' =>(object) array ( 'sub_name' => 'Volvo', 'sub_id' => 'volvo', 'dir_id' => 'bus' ), ); $dataArray = array(); $parentfolder = array(); foreach( $subdirectory as $sub ) { $dirName = $sub->dir_id; if( !isset( $dataArray[$dirName] ) ) { $dataArray[$dirName] = array(); } $dataArray[$dirName][] = array('id' => $sub->sub_id, 'value' => $sub->sub_name); } foreach ($directory as $dir ) { $dirName = $dir->dir_id; if( isset ( $dataArray[$dirName] ) ) { $data = $dataArray[$dirName]; } else { $data = array(); } $parentfolder[] = array('id' => $dir->dir_id, 'value' => $dir->dir_name, 'data' => $data); } echo json_encode($parentfolder);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 15, Position 2 = 31
Branch analysis from position: 15
2 jumps found. (Code = 78) Position 1 = 16, Position 2 = 31
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 23
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 23
Branch analysis from position: 31
2 jumps found. (Code = 77) Position 1 = 33, Position 2 = 50
Branch analysis from position: 33
2 jumps found. (Code = 78) Position 1 = 34, Position 2 = 50
Branch analysis from position: 34
2 jumps found. (Code = 43) Position 1 = 38, Position 2 = 41
Branch analysis from position: 38
1 jumps found. (Code = 42) Position 1 = 42
Branch analysis from position: 42
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
Branch analysis from position: 50
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 50
Branch analysis from position: 31
filename:       /in/ZkfLc
function name:  (null)
number of ops:  56
compiled vars:  !0 = $directory, !1 = $subdirectory, !2 = $dataArray, !3 = $parentfolder, !4 = $sub, !5 = $dirName, !6 = $dir, !7 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   CAST                                          8  ~8      <array>
          1        INIT_ARRAY                                       ~9      ~8, 0
   10     2        CAST                                          8  ~10     <array>
          3        ADD_ARRAY_ELEMENT                                ~9      ~10, 1
   14     4        CAST                                          8  ~11     <array>
          5        ADD_ARRAY_ELEMENT                                ~9      ~11, 2
    4     6        ASSIGN                                                   !0, ~9
   21     7        CAST                                          8  ~13     <array>
          8        INIT_ARRAY                                       ~14     ~13, 0
   26     9        CAST                                          8  ~15     <array>
         10        ADD_ARRAY_ELEMENT                                ~14     ~15, 1
   19    11        ASSIGN                                                   !1, ~14
   33    12        ASSIGN                                                   !2, <array>
   34    13        ASSIGN                                                   !3, <array>
   36    14      > FE_RESET_R                                       $19     !1, ->31
         15    > > FE_FETCH_R                                               $19, !4, ->31
   37    16    >   FETCH_OBJ_R                                      ~20     !4, 'dir_id'
         17        ASSIGN                                                   !5, ~20
   38    18        ISSET_ISEMPTY_DIM_OBJ                         0  ~22     !2, !5
         19        BOOL_NOT                                         ~23     ~22
         20      > JMPZ                                                     ~23, ->23
   39    21    >   ASSIGN_DIM                                               !2, !5
         22        OP_DATA                                                  <array>
   41    23    >   FETCH_OBJ_R                                      ~27     !4, 'sub_id'
         24        INIT_ARRAY                                       ~28     ~27, 'id'
         25        FETCH_OBJ_R                                      ~29     !4, 'sub_name'
         26        ADD_ARRAY_ELEMENT                                ~28     ~29, 'value'
         27        FETCH_DIM_W                                      $25     !2, !5
         28        ASSIGN_DIM                                               $25
         29        OP_DATA                                                  ~28
   36    30      > JMP                                                      ->15
         31    >   FE_FREE                                                  $19
   44    32      > FE_RESET_R                                       $30     !0, ->50
         33    > > FE_FETCH_R                                               $30, !6, ->50
   45    34    >   FETCH_OBJ_R                                      ~31     !6, 'dir_id'
         35        ASSIGN                                                   !5, ~31
   46    36        ISSET_ISEMPTY_DIM_OBJ                         0          !2, !5
         37      > JMPZ                                                     ~33, ->41
   47    38    >   FETCH_DIM_R                                      ~34     !2, !5
         39        ASSIGN                                                   !7, ~34
         40      > JMP                                                      ->42
   49    41    >   ASSIGN                                                   !7, <array>
   51    42    >   FETCH_OBJ_R                                      ~38     !6, 'dir_id'
         43        INIT_ARRAY                                       ~39     ~38, 'id'
         44        FETCH_OBJ_R                                      ~40     !6, 'dir_name'
         45        ADD_ARRAY_ELEMENT                                ~39     ~40, 'value'
         46        ADD_ARRAY_ELEMENT                                ~39     !7, 'data'
         47        ASSIGN_DIM                                               !3
         48        OP_DATA                                                  ~39
   44    49      > JMP                                                      ->33
         50    >   FE_FREE                                                  $30
   54    51        INIT_FCALL                                               'json_encode'
         52        SEND_VAR                                                 !3
         53        DO_ICALL                                         $41     
         54        ECHO                                                     $41
         55      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
177.52 ms | 1400 KiB | 15 Q