3v4l.org

run code in 300+ PHP versions simultaneously
<?php const DATA = [ [1070, 1023, 'this is the first record'], [1070, 1028, 'this is the second record'], [1098, 1023, 'this is the thrid record'], [1098, 1028, 'this is the fourth record'], [2021, 1023, 'this is the fifth record'], [2021, 1028, 'this is the sixth record'], ]; function group_records(array $data, int $col) { $last = null; $current = []; foreach (DATA as $row) { if ($row[$col] !== $last && $last !== null) { yield $last => $current; $last = null; $current = []; } $last = $row[$col]; $current[] = $row; } if ($last !== null) { yield $last => $current; } } foreach (group_records(DATA, 0) as $key => $rows) { echo "$key:\n"; foreach ($rows as $row) echo " " . implode('|', $row) . "\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 24
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 24
Branch analysis from position: 8
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 22
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 22
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 22
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
filename:       /in/03T3h
function name:  (null)
number of ops:  26
compiled vars:  !0 = $rows, !1 = $key, !2 = $row
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   DECLARE_CONST                                            'DATA', <array>
   33     1        INIT_FCALL                                               'group_records'
          2        FETCH_CONSTANT                                   ~3      'DATA'
          3        SEND_VAL                                                 ~3
          4        SEND_VAL                                                 0
          5        DO_FCALL                                      0  $4      
          6      > FE_RESET_R                                       $5      $4, ->24
          7    > > FE_FETCH_R                                       ~6      $5, !0, ->24
          8    >   ASSIGN                                                   !1, ~6
   34     9        NOP                                                      
         10        FAST_CONCAT                                      ~8      !1, '%3A%0A'
         11        ECHO                                                     ~8
   35    12      > FE_RESET_R                                       $9      !0, ->22
         13    > > FE_FETCH_R                                               $9, !2, ->22
         14    >   INIT_FCALL                                               'implode'
         15        SEND_VAL                                                 '%7C'
         16        SEND_VAR                                                 !2
         17        DO_ICALL                                         $10     
         18        CONCAT                                           ~11     '++', $10
         19        CONCAT                                           ~12     ~11, '%0A'
         20        ECHO                                                     ~12
         21      > JMP                                                      ->13
         22    >   FE_FREE                                                  $9
   33    23      > JMP                                                      ->7
         24    >   FE_FREE                                                  $5
   36    25      > RETURN                                                   1

Function group_records:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 22
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 22
Branch analysis from position: 8
2 jumps found. (Code = 46) Position 1 = 11, Position 2 = 13
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 17
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 17
Branch analysis from position: 13
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 26
Branch analysis from position: 25
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 26
Branch analysis from position: 22
filename:       /in/03T3h
function name:  group_records
number of ops:  27
compiled vars:  !0 = $data, !1 = $col, !2 = $last, !3 = $current, !4 = $row
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        GENERATOR_CREATE                                         
   14     3        ASSIGN                                                   !2, null
   15     4        ASSIGN                                                   !3, <array>
   17     5        FETCH_CONSTANT                                   ~7      'DATA'
          6      > FE_RESET_R                                       $8      ~7, ->22
          7    > > FE_FETCH_R                                               $8, !4, ->22
   18     8    >   FETCH_DIM_R                                      ~9      !4, !1
          9        IS_NOT_IDENTICAL                                 ~10     !2, ~9
         10      > JMPZ_EX                                          ~10     ~10, ->13
         11    >   TYPE_CHECK                                  1020  ~11     !2
         12        BOOL                                             ~10     ~11
         13    > > JMPZ                                                     ~10, ->17
   19    14    >   YIELD                                                    !3, !2
   20    15        ASSIGN                                                   !2, null
   21    16        ASSIGN                                                   !3, <array>
   24    17    >   FETCH_DIM_R                                      ~15     !4, !1
         18        ASSIGN                                                   !2, ~15
   25    19        ASSIGN_DIM                                               !3
         20        OP_DATA                                                  !4
   17    21      > JMP                                                      ->7
         22    >   FE_FREE                                                  $8
   28    23        TYPE_CHECK                                  1020          !2
         24      > JMPZ                                                     ~18, ->26
   29    25    >   YIELD                                                    !3, !2
   31    26    > > GENERATOR_RETURN                                         

End of function group_records

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
139.82 ms | 1005 KiB | 15 Q