3v4l.org

run code in 300+ PHP versions simultaneously
<?php $the_array = [ ['id' => 1, 'value' => 10, 'name' => 'apple'], ['id' => 1, 'value' => 20, 'name' => 'orange'], ['id' => 1, 'value' => 30, 'name' => 'banana'], ['id' => 2, 'value' => 100, 'name' => 'car'], ['id' => 2, 'value' => 200, 'name' => 'bicycle'], ]; $result = []; foreach ($the_array as $row) { if (!isset($result[$row['id']])) { $result[$row['id']] = $row; } else { $result[$row['id']]['value'] += $row['value']; $result[$row['id']]['name'] .= ",{$row['name']}"; } } var_export(array_values($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
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 12
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 12
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/tEKBC
function name:  (null)
number of ops:  33
compiled vars:  !0 = $the_array, !1 = $result, !2 = $row
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   11     1        ASSIGN                                                   !1, <array>
   12     2      > FE_RESET_R                                       $5      !0, ->25
          3    > > FE_FETCH_R                                               $5, !2, ->25
   13     4    >   FETCH_DIM_R                                      ~6      !2, 'id'
          5        ISSET_ISEMPTY_DIM_OBJ                         0  ~7      !1, ~6
          6        BOOL_NOT                                         ~8      ~7
          7      > JMPZ                                                     ~8, ->12
   14     8    >   FETCH_DIM_R                                      ~9      !2, 'id'
          9        ASSIGN_DIM                                               !1, ~9
         10        OP_DATA                                                  !2
   13    11      > JMP                                                      ->24
   16    12    >   FETCH_DIM_R                                      ~11     !2, 'id'
         13        FETCH_DIM_R                                      ~14     !2, 'value'
         14        FETCH_DIM_RW                                     $12     !1, ~11
         15        ASSIGN_DIM_OP                +=               1          $12, 'value'
         16        OP_DATA                                                  ~14
   17    17        FETCH_DIM_R                                      ~15     !2, 'id'
         18        NOP                                                      
         19        FETCH_DIM_R                                      ~18     !2, 'name'
         20        FAST_CONCAT                                      ~19     '%2C', ~18
         21        FETCH_DIM_RW                                     $16     !1, ~15
         22        ASSIGN_DIM_OP                .=               8          $16, 'name'
         23        OP_DATA                                                  ~19
   12    24    > > JMP                                                      ->3
         25    >   FE_FREE                                                  $5
   20    26        INIT_FCALL                                               'var_export'
         27        INIT_FCALL                                               'array_values'
         28        SEND_VAR                                                 !1
         29        DO_ICALL                                         $20     
         30        SEND_VAR                                                 $20
         31        DO_ICALL                                                 
         32      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
138.56 ms | 1000 KiB | 15 Q