3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ ['color' => '#000000', 'size' => 'L', 'count' => 2], ['color' => '#000000', 'size' => 'XL', 'count' => 1], ['color' => '#ffffff', 'size' => 'L','count' => 2], ['color' => '#ffffff', 'size' => 'XL', 'count' => 1], ['color' => '#ff0000', 'size' => 'L', 'count' => 1] ]; $result = []; foreach ($array as $row) { extract($row); if (!isset($result[$color])) { $result[$color] = $row; } elseif (isset($result[$color]['count'])) { $result[$color]['size'] = [ [ 'value' => $result[$color]['size'], 'count' => $result[$color]['count'] ], [ 'value' => $size, 'count' => $count ] ]; unset($result[$color]['count']); } else { $result[$color]['size'][] = [ 'value' => $size, 'count' => $count ]; } } echo json_encode(array_values($result), JSON_PRETTY_PRINT);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 39
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 39
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 13
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 32
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 39
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 39
filename:       /in/NmYbj
function name:  (null)
number of ops:  49
compiled vars:  !0 = $array, !1 = $result, !2 = $row, !3 = $color, !4 = $size, !5 = $count
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                                       $8      !0, ->39
          3    > > FE_FETCH_R                                               $8, !2, ->39
   13     4    >   INIT_FCALL                                               'extract'
          5        SEND_REF                                                 !2
          6        DO_ICALL                                                 
   14     7        ISSET_ISEMPTY_DIM_OBJ                         0  ~10     !1, !3
          8        BOOL_NOT                                         ~11     ~10
          9      > JMPZ                                                     ~11, ->13
   15    10    >   ASSIGN_DIM                                               !1, !3
         11        OP_DATA                                                  !2
   14    12      > JMP                                                      ->38
   16    13    >   FETCH_DIM_IS                                     ~13     !1, !3
         14        ISSET_ISEMPTY_DIM_OBJ                         0          ~13, 'count'
         15      > JMPZ                                                     ~14, ->32
   19    16    >   FETCH_DIM_R                                      ~17     !1, !3
         17        FETCH_DIM_R                                      ~18     ~17, 'size'
         18        INIT_ARRAY                                       ~19     ~18, 'value'
   20    19        FETCH_DIM_R                                      ~20     !1, !3
         20        FETCH_DIM_R                                      ~21     ~20, 'count'
         21        ADD_ARRAY_ELEMENT                                ~19     ~21, 'count'
         22        INIT_ARRAY                                       ~22     ~19
   23    23        INIT_ARRAY                                       ~23     !4, 'value'
   24    24        ADD_ARRAY_ELEMENT                                ~23     !5, 'count'
         25        ADD_ARRAY_ELEMENT                                ~22     ~23
   17    26        FETCH_DIM_W                                      $15     !1, !3
         27        ASSIGN_DIM                                               $15, 'size'
   24    28        OP_DATA                                                  ~22
   27    29        FETCH_DIM_UNSET                                  $24     !1, !3
         30        UNSET_DIM                                                $24, 'count'
   16    31      > JMP                                                      ->38
   30    32    >   INIT_ARRAY                                       ~28     !4, 'value'
   31    33        ADD_ARRAY_ELEMENT                                ~28     !5, 'count'
   29    34        FETCH_DIM_W                                      $25     !1, !3
         35        FETCH_DIM_W                                      $26     $25, 'size'
         36        ASSIGN_DIM                                               $26
   31    37        OP_DATA                                                  ~28
   12    38    > > JMP                                                      ->3
         39    >   FE_FREE                                                  $8
   35    40        INIT_FCALL                                               'json_encode'
         41        INIT_FCALL                                               'array_values'
         42        SEND_VAR                                                 !1
         43        DO_ICALL                                         $29     
         44        SEND_VAR                                                 $29
         45        SEND_VAL                                                 128
         46        DO_ICALL                                         $30     
         47        ECHO                                                     $30
         48      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
136.85 ms | 1007 KiB | 16 Q