3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Everything you enter here will be executed by our servers. Try it! $data = array( array( 'id' => 1, 'name' => 'bob', 'product_id' => 1, 'product' => 'laptop', 'price' => 999, ), array( 'id' => 1, 'name' => 'bob', 'product_id' => 2, 'product' => 'mouse', 'price' => 15, ), array( 'id' => 1, 'name' => 'bob', 'product_id' => 3, 'product' => 'keyboard', 'price' => 25, ) ); $output = array(); $userColumnIntersect = array_flip(array( 'id', 'name', )); $productColumnIntersect = array_flip(array( 'product', 'price', )); foreach($data as $row){ $id = $row['id']; if(!isset($output[$id])){ $output[$id] = array_intersect_key($row, $userColumnIntersect); $output[$id]['products'] = array(); } $productId = $row['product_id']; if(!isset($output[$id]['products'][$productId])){ $productDataRow = array_intersect_key($row, $productColumnIntersect); $output[$id]['products'][$productId] = $productDataRow; } } echo '<pre>'; print_r($output);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 11, Position 2 = 43
Branch analysis from position: 11
2 jumps found. (Code = 78) Position 1 = 12, Position 2 = 43
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 26
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 33, Position 2 = 42
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 42
Branch analysis from position: 26
Branch analysis from position: 43
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 43
filename:       /in/cqYa2
function name:  (null)
number of ops:  49
compiled vars:  !0 = $data, !1 = $output, !2 = $userColumnIntersect, !3 = $productColumnIntersect, !4 = $row, !5 = $id, !6 = $productId, !7 = $productDataRow
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   ASSIGN                                                   !0, <array>
   30     1        ASSIGN                                                   !1, <array>
   32     2        INIT_FCALL                                               'array_flip'
   33     3        SEND_VAL                                                 <array>
          4        DO_ICALL                                         $10     
   32     5        ASSIGN                                                   !2, $10
   37     6        INIT_FCALL                                               'array_flip'
   38     7        SEND_VAL                                                 <array>
          8        DO_ICALL                                         $12     
   37     9        ASSIGN                                                   !3, $12
   41    10      > FE_RESET_R                                       $14     !0, ->43
         11    > > FE_FETCH_R                                               $14, !4, ->43
   43    12    >   FETCH_DIM_R                                      ~15     !4, 'id'
         13        ASSIGN                                                   !5, ~15
   45    14        ISSET_ISEMPTY_DIM_OBJ                         0  ~17     !1, !5
         15        BOOL_NOT                                         ~18     ~17
         16      > JMPZ                                                     ~18, ->26
   46    17    >   INIT_FCALL                                               'array_intersect_key'
         18        SEND_VAR                                                 !4
         19        SEND_VAR                                                 !2
         20        DO_ICALL                                         $20     
         21        ASSIGN_DIM                                               !1, !5
         22        OP_DATA                                                  $20
   47    23        FETCH_DIM_W                                      $21     !1, !5
         24        ASSIGN_DIM                                               $21, 'products'
         25        OP_DATA                                                  <array>
   50    26    >   FETCH_DIM_R                                      ~23     !4, 'product_id'
         27        ASSIGN                                                   !6, ~23
   52    28        FETCH_DIM_IS                                     ~25     !1, !5
         29        FETCH_DIM_IS                                     ~26     ~25, 'products'
         30        ISSET_ISEMPTY_DIM_OBJ                         0  ~27     ~26, !6
         31        BOOL_NOT                                         ~28     ~27
         32      > JMPZ                                                     ~28, ->42
   53    33    >   INIT_FCALL                                               'array_intersect_key'
         34        SEND_VAR                                                 !4
         35        SEND_VAR                                                 !3
         36        DO_ICALL                                         $29     
         37        ASSIGN                                                   !7, $29
   54    38        FETCH_DIM_W                                      $31     !1, !5
         39        FETCH_DIM_W                                      $32     $31, 'products'
         40        ASSIGN_DIM                                               $32, !6
         41        OP_DATA                                                  !7
   41    42    > > JMP                                                      ->11
         43    >   FE_FREE                                                  $14
   59    44        ECHO                                                     '%3Cpre%3E'
   60    45        INIT_FCALL                                               'print_r'
         46        SEND_VAR                                                 !1
         47        DO_ICALL                                                 
         48      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.2 ms | 1392 KiB | 19 Q