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 ]; $result = []; foreach ($line_items as $row) { $lastKey = array_key_last($result); if ( !$result || array_sum(array_column($result[$lastKey], 'price')) == $price_array[$lastKey] ) { unset($ref); $result[] = &$ref; } $ref[] = $row; } var_export($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 29
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 29
Branch analysis from position: 5
2 jumps found. (Code = 47) Position 1 = 11, Position 2 = 22
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 26
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 26
Branch analysis from position: 22
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
filename:       /in/q0p6Q
function name:  (null)
number of ops:  34
compiled vars:  !0 = $line_items, !1 = $price_array, !2 = $result, !3 = $row, !4 = $lastKey, !5 = $ref
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    8     1        ASSIGN                                                   !1, <array>
   13     2        ASSIGN                                                   !2, <array>
   14     3      > FE_RESET_R                                       $9      !0, ->29
          4    > > FE_FETCH_R                                               $9, !3, ->29
   15     5    >   INIT_FCALL                                               'array_key_last'
          6        SEND_VAR                                                 !2
          7        DO_ICALL                                         $10     
          8        ASSIGN                                                   !4, $10
   17     9        BOOL_NOT                                         ~12     !2
         10      > JMPNZ_EX                                         ~12     ~12, ->22
   18    11    >   INIT_FCALL                                               'array_sum'
         12        INIT_FCALL                                               'array_column'
         13        FETCH_DIM_R                                      ~13     !2, !4
         14        SEND_VAL                                                 ~13
         15        SEND_VAL                                                 'price'
         16        DO_ICALL                                         $14     
         17        SEND_VAR                                                 $14
         18        DO_ICALL                                         $15     
         19        FETCH_DIM_R                                      ~16     !1, !4
         20        IS_EQUAL                                         ~17     $15, ~16
         21        BOOL                                             ~12     ~17
         22    > > JMPZ                                                     ~12, ->26
   21    23    >   UNSET_CV                                                 !5
   22    24        FETCH_DIM_W                                      $18     !2
         25        ASSIGN_REF                                               $18, !5
   24    26    >   ASSIGN_DIM                                               !5
         27        OP_DATA                                                  !3
   14    28      > JMP                                                      ->4
         29    >   FE_FREE                                                  $9
   26    30        INIT_FCALL                                               'var_export'
         31        SEND_VAR                                                 !2
         32        DO_ICALL                                                 
         33      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
135.97 ms | 1002 KiB | 17 Q