3v4l.org

run code in 300+ PHP versions simultaneously
<?php $input = [1, 1, 1, 2, 2, 2, 1, 1, 2, 2, 1]; $output = []; $idx = -1; $prev = null; foreach($input as $val) { if($prev !== $val) { ++$idx; } $output[$idx][] = $val; $prev = $val; } print_r($output);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 14
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 14
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 9
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 9
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
filename:       /in/c2Irh
function name:  (null)
number of ops:  19
compiled vars:  !0 = $input, !1 = $output, !2 = $idx, !3 = $prev, !4 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    5     1        ASSIGN                                                   !1, <array>
    6     2        ASSIGN                                                   !2, -1
    7     3        ASSIGN                                                   !3, null
    8     4      > FE_RESET_R                                       $9      !0, ->14
          5    > > FE_FETCH_R                                               $9, !4, ->14
    9     6    >   IS_NOT_IDENTICAL                                         !3, !4
          7      > JMPZ                                                     ~10, ->9
   10     8    >   PRE_INC                                                  !2
   12     9    >   FETCH_DIM_W                                      $12     !1, !2
         10        ASSIGN_DIM                                               $12
         11        OP_DATA                                                  !4
   13    12        ASSIGN                                                   !3, !4
    8    13      > JMP                                                      ->5
         14    >   FE_FREE                                                  $9
   16    15        INIT_FCALL                                               'print_r'
         16        SEND_VAR                                                 !1
         17        DO_ICALL                                                 
         18      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
168.02 ms | 1386 KiB | 15 Q