3v4l.org

run code in 300+ PHP versions simultaneously
<?php $data = [['id' => 972, 'grouped_by' => 1], ['id' => 664, 'grouped_by' => 4], ['id' => 631, 'grouped_by' => 4], ['id' => 630, 'grouped_by' => 1], ['id' => 971, 'grouped_by' => 1], ['id' => 973, 'grouped_by' => 1], ['id' => 974, 'grouped_by' => 1]]; $grouped_result = $grouped_by_counts = []; $previous_grouped_by = null; // a value that will never occur in the data foreach($data as $datum) { if($datum['grouped_by'] !== $previous_grouped_by) { $grouped_by_counts[$datum['grouped_by']] = isset($grouped_by_counts[$datum['grouped_by']]) ? $grouped_by_counts[$datum['grouped_by']] + 1 : 1; } $grouped_result[ $datum['grouped_by'].'.'.$grouped_by_counts[$datum['grouped_by']] ][] = $datum; $previous_grouped_by = $datum['grouped_by']; } print_r($grouped_result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 32
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 32
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 21
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 18
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 21
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 32
filename:       /in/odtie
function name:  (null)
number of ops:  37
compiled vars:  !0 = $data, !1 = $grouped_result, !2 = $grouped_by_counts, !3 = $previous_grouped_by, !4 = $datum
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    5     1        ASSIGN                                           ~6      !2, <array>
          2        ASSIGN                                                   !1, ~6
    6     3        ASSIGN                                                   !3, null
    8     4      > FE_RESET_R                                       $9      !0, ->32
          5    > > FE_FETCH_R                                               $9, !4, ->32
    9     6    >   FETCH_DIM_R                                      ~10     !4, 'grouped_by'
          7        IS_NOT_IDENTICAL                                         !3, ~10
          8      > JMPZ                                                     ~11, ->21
   10     9    >   FETCH_DIM_R                                      ~12     !4, 'grouped_by'
   11    10        FETCH_DIM_R                                      ~14     !4, 'grouped_by'
         11        ISSET_ISEMPTY_DIM_OBJ                         0          !2, ~14
         12      > JMPZ                                                     ~15, ->18
   12    13    >   FETCH_DIM_R                                      ~16     !4, 'grouped_by'
         14        FETCH_DIM_R                                      ~17     !2, ~16
         15        ADD                                              ~18     ~17, 1
         16        QM_ASSIGN                                        ~19     ~18
         17      > JMP                                                      ->19
         18    >   QM_ASSIGN                                        ~19     1
   10    19    >   ASSIGN_DIM                                               !2, ~12
   12    20        OP_DATA                                                  ~19
   15    21    >   FETCH_DIM_R                                      ~20     !4, 'grouped_by'
         22        CONCAT                                           ~21     ~20, '.'
         23        FETCH_DIM_R                                      ~22     !4, 'grouped_by'
         24        FETCH_DIM_R                                      ~23     !2, ~22
         25        CONCAT                                           ~24     ~21, ~23
         26        FETCH_DIM_W                                      $25     !1, ~24
         27        ASSIGN_DIM                                               $25
   16    28        OP_DATA                                                  !4
   17    29        FETCH_DIM_R                                      ~27     !4, 'grouped_by'
         30        ASSIGN                                                   !3, ~27
    8    31      > JMP                                                      ->5
         32    >   FE_FREE                                                  $9
   20    33        INIT_FCALL                                               'print_r'
         34        SEND_VAR                                                 !1
         35        DO_ICALL                                                 
         36      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
247.33 ms | 1010 KiB | 14 Q