3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = array( array( 'foo' => 1, 'bar' => 2, 'thing' => 'apple' ), array( 'foo' => 1, 'bar' => 2, 'thing' => 'orange' ), array( 'foo' => 2, 'bar' => 2, 'thing' => 'apple' ), ); $newArr = $keys = array(); foreach ($arr as $row) { if (isset($keys[$row['foo']][$row['bar']])) { $newArr[$keys[$row['foo']][$row['bar']]]['thing'][] = $row['thing']; } else { $keys[$row['foo']][$row['bar']] = array_push($newArr, $row) - 1; $newArr[$keys[$row['foo']][$row['bar']]]['thing'] = array($row['thing']); } } unset($keys); print_r($newArr);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 40
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 40
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 20
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 39
Branch analysis from position: 39
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 40
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 40
filename:       /in/4IZXU
function name:  (null)
number of ops:  46
compiled vars:  !0 = $arr, !1 = $newArr, !2 = $keys, !3 = $row
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   21     1        ASSIGN                                           ~5      !2, <array>
          2        ASSIGN                                                   !1, ~5
   22     3      > FE_RESET_R                                       $7      !0, ->40
          4    > > FE_FETCH_R                                               $7, !3, ->40
   23     5    >   FETCH_DIM_R                                      ~8      !3, 'foo'
          6        FETCH_DIM_R                                      ~10     !3, 'bar'
          7        FETCH_DIM_IS                                     ~9      !2, ~8
          8        ISSET_ISEMPTY_DIM_OBJ                         0          ~9, ~10
          9      > JMPZ                                                     ~11, ->20
   24    10    >   FETCH_DIM_R                                      ~12     !3, 'foo'
         11        FETCH_DIM_R                                      ~14     !3, 'bar'
         12        FETCH_DIM_R                                      ~13     !2, ~12
         13        FETCH_DIM_R                                      ~15     ~13, ~14
         14        FETCH_DIM_R                                      ~19     !3, 'thing'
         15        FETCH_DIM_W                                      $16     !1, ~15
         16        FETCH_DIM_W                                      $17     $16, 'thing'
         17        ASSIGN_DIM                                               $17
         18        OP_DATA                                                  ~19
   23    19      > JMP                                                      ->39
   26    20    >   FETCH_DIM_R                                      ~20     !3, 'foo'
         21        FETCH_DIM_R                                      ~22     !3, 'bar'
         22        INIT_FCALL                                               'array_push'
         23        SEND_REF                                                 !1
         24        SEND_VAR                                                 !3
         25        DO_ICALL                                         $24     
         26        SUB                                              ~25     $24, 1
         27        FETCH_DIM_W                                      $21     !2, ~20
         28        ASSIGN_DIM                                               $21, ~22
         29        OP_DATA                                                  ~25
   27    30        FETCH_DIM_R                                      ~26     !3, 'foo'
         31        FETCH_DIM_R                                      ~28     !3, 'bar'
         32        FETCH_DIM_R                                      ~27     !2, ~26
         33        FETCH_DIM_R                                      ~29     ~27, ~28
         34        FETCH_DIM_R                                      ~32     !3, 'thing'
         35        INIT_ARRAY                                       ~33     ~32
         36        FETCH_DIM_W                                      $30     !1, ~29
         37        ASSIGN_DIM                                               $30, 'thing'
         38        OP_DATA                                                  ~33
   22    39    > > JMP                                                      ->4
         40    >   FE_FREE                                                  $7
   30    41        UNSET_CV                                                 !2
   32    42        INIT_FCALL                                               'print_r'
         43        SEND_VAR                                                 !1
         44        DO_ICALL                                                 
         45      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.9 ms | 1016 KiB | 15 Q