3v4l.org

run code in 300+ PHP versions simultaneously
<?php $line_items = [ ['price' => 41.99, 'id' => 12, 'quantity' => 1], ['price' => 155.95, 'id' => 11, 'quantity' => 1], ['price' => 21, 'id' => 13, 'quantity' => 1] ]; $price_array = [ 197.94, 21.00 ]; $bucket_sum = 0; $bucket_index = 0; $result = []; foreach ($line_items as $row) { $result[$bucket_index][] = $row; $bucket_sum += $row['price']; if ($bucket_sum >= $price_array[$bucket_index]) { $bucket_sum = 0; ++$bucket_index; } } var_export($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 18
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 18
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 17
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 17
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
filename:       /in/XMsmK
function name:  (null)
number of ops:  23
compiled vars:  !0 = $line_items, !1 = $price_array, !2 = $bucket_sum, !3 = $bucket_index, !4 = $result, !5 = $row
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    8     1        ASSIGN                                                   !1, <array>
   13     2        ASSIGN                                                   !2, 0
   14     3        ASSIGN                                                   !3, 0
   15     4        ASSIGN                                                   !4, <array>
   16     5      > FE_RESET_R                                       $11     !0, ->18
          6    > > FE_FETCH_R                                               $11, !5, ->18
   17     7    >   FETCH_DIM_W                                      $12     !4, !3
          8        ASSIGN_DIM                                               $12
          9        OP_DATA                                                  !5
   18    10        FETCH_DIM_R                                      ~14     !5, 'price'
         11        ASSIGN_OP                                     1          !2, ~14
   19    12        FETCH_DIM_R                                      ~16     !1, !3
         13        IS_SMALLER_OR_EQUAL                                      ~16, !2
         14      > JMPZ                                                     ~17, ->17
   20    15    >   ASSIGN                                                   !2, 0
   21    16        PRE_INC                                                  !3
   16    17    > > JMP                                                      ->6
         18    >   FE_FREE                                                  $11
   24    19        INIT_FCALL                                               'var_export'
         20        SEND_VAR                                                 !4
         21        DO_ICALL                                                 
         22      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
138.38 ms | 997 KiB | 14 Q