3v4l.org

run code in 500+ PHP versions simultaneously
<?php $arr = Array ( 0 => 'world', 1 => 'is', 2 => 'a', 3 => 'wonderfull', 5 => 'in', 6 => 'our' ); $new_array = []; $old_key = -1; $i = 0; foreach($arr as $key=>$val){ if(($key-$old_key) ==1){ $new_array[$i][] = $val; $old_key = $key; } if(($key-$old_key) >1){ $i++; $new_array[$i][] = $val; $old_key = $key; } } print_r($new_array);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 23
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 23
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 14
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 22
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 22
Branch analysis from position: 14
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
filename:       /in/Yl9rp
function name:  (null)
number of ops:  28
compiled vars:  !0 = $arr, !1 = $new_array, !2 = $old_key, !3 = $i, !4 = $val, !5 = $key
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
   13     1        ASSIGN                                                       !1, <array>
   14     2        ASSIGN                                                       !2, -1
   15     3        ASSIGN                                                       !3, 0
   16     4      > FE_RESET_R                                           $10     !0, ->23
          5    > > FE_FETCH_R                                           ~11     $10, !4, ->23
          6    >   ASSIGN                                                       !5, ~11
   17     7        SUB                                                  ~13     !5, !2
          8        IS_EQUAL                                                     ~13, 1
          9      > JMPZ                                                         ~14, ->14
   18    10    >   FETCH_DIM_W                                          $15     !1, !3
         11        ASSIGN_DIM                                                   $15
         12        OP_DATA                                                      !4
   19    13        ASSIGN                                                       !2, !5
   21    14    >   SUB                                                  ~18     !5, !2
         15        IS_SMALLER                                                   1, ~18
         16      > JMPZ                                                         ~19, ->22
   22    17    >   PRE_INC                                                      !3
   23    18        FETCH_DIM_W                                          $21     !1, !3
         19        ASSIGN_DIM                                                   $21
         20        OP_DATA                                                      !4
   24    21        ASSIGN                                                       !2, !5
   16    22    > > JMP                                                          ->5
         23    >   FE_FREE                                                      $10
   27    24        INIT_FCALL                                                   'print_r'
         25        SEND_VAR                                                     !1
         26        DO_ICALL                                                     
         27      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
168.34 ms | 2272 KiB | 14 Q