3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ [ 'id' => 112, 'name' => 'John', 'country' => 'Spain', 'age' => 24, 'company' => 'One', 'price' => 10 ], [ 'id' => 112, 'name' => 'John', 'country' => 'Spain', 'age' => 24, 'company' => 'Two', 'price' => 15 ], [ 'id' => 112, 'name' => 'John', 'country' => 'Spain', 'age' => 24, 'company' => 'Three', 'price' => 20 ], [ 'id' => 224, 'name' => 'Paul', 'country' => 'France', 'age' => 25, 'company' => 'One', 'price' => 25 ], [ 'id' => 224, 'name' => 'Paul', 'country' => 'France', 'age' => 25, 'company' => 'Two', 'price' => 40 ] ]; $result = []; foreach ($array as $row) { $companies = array_splice($row, -2); $result[$row['id']] ??= $row; $result[$row['id']]['companies'][] = $companies; } var_export($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 25
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 25
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
filename:       /in/m5N3R
function name:  (null)
number of ops:  30
compiled vars:  !0 = $array, !1 = $result, !2 = $row, !3 = $companies
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   46     1        ASSIGN                                                   !1, <array>
   47     2      > FE_RESET_R                                       $6      !0, ->25
          3    > > FE_FETCH_R                                               $6, !2, ->25
   48     4    >   INIT_FCALL                                               'array_splice'
          5        SEND_REF                                                 !2
          6        SEND_VAL                                                 -2
          7        DO_ICALL                                         $7      
          8        ASSIGN                                                   !3, $7
   49     9        FETCH_DIM_R                                      ~9      !2, 'id'
         10        COPY_TMP                                         ~10     ~9
         11        FETCH_DIM_IS                                     ~11     !1, ~9
         12        COALESCE                                         ~12     ~11
         13        ASSIGN_DIM                                       ~13     !1, ~10
         14        OP_DATA                                                  !2
         15        QM_ASSIGN                                        ~12     ~13
         16      > JMP                                                      ->18
         17*       FREE                                                     ~10
         18    >   FREE                                                     ~12
   50    19        FETCH_DIM_R                                      ~14     !2, 'id'
         20        FETCH_DIM_W                                      $15     !1, ~14
         21        FETCH_DIM_W                                      $16     $15, 'companies'
         22        ASSIGN_DIM                                               $16
         23        OP_DATA                                                  !3
   47    24      > JMP                                                      ->3
         25    >   FE_FREE                                                  $6
   52    26        INIT_FCALL                                               'var_export'
         27        SEND_VAR                                                 !1
         28        DO_ICALL                                                 
         29      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
145.88 ms | 1007 KiB | 15 Q