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 ]; var_export( array_reduce( $line_items, function($result, $row) use ($price_array) { $index = (int) array_key_last($result); $index += array_sum(array_column($result[$index] ?? [], 'price')) == $price_array[$index]; $result[$index][] = $row; return $result; }, [] ) );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/L36bd
function name:  (null)
number of ops:  13
compiled vars:  !0 = $line_items, !1 = $price_array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    8     1        ASSIGN                                                   !1, <array>
   13     2        INIT_FCALL                                               'var_export'
   14     3        INIT_FCALL                                               'array_reduce'
   15     4        SEND_VAR                                                 !0
   16     5        DECLARE_LAMBDA_FUNCTION                          ~4      [0]
          6        BIND_LEXICAL                                             ~4, !1
   21     7        SEND_VAL                                                 ~4
   22     8        SEND_VAL                                                 <array>
   14     9        DO_ICALL                                         $5      
   22    10        SEND_VAR                                                 $5
   13    11        DO_ICALL                                                 
   24    12      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/L36bd
function name:  {closure}
number of ops:  26
compiled vars:  !0 = $result, !1 = $row, !2 = $price_array, !3 = $index
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        BIND_STATIC                                              !2
   17     3        INIT_FCALL                                               'array_key_last'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $4      
          6        CAST                                          4  ~5      $4
          7        ASSIGN                                                   !3, ~5
   18     8        INIT_FCALL                                               'array_sum'
          9        INIT_FCALL                                               'array_column'
         10        FETCH_DIM_IS                                     ~7      !0, !3
         11        COALESCE                                         ~8      ~7
         12        QM_ASSIGN                                        ~8      <array>
         13        SEND_VAL                                                 ~8
         14        SEND_VAL                                                 'price'
         15        DO_ICALL                                         $9      
         16        SEND_VAR                                                 $9
         17        DO_ICALL                                         $10     
         18        FETCH_DIM_R                                      ~11     !2, !3
         19        IS_EQUAL                                         ~12     $10, ~11
         20        ASSIGN_OP                                     1          !3, ~12
   19    21        FETCH_DIM_W                                      $14     !0, !3
         22        ASSIGN_DIM                                               $14
         23        OP_DATA                                                  !1
   20    24      > RETURN                                                   !0
   21    25*     > RETURN                                                   null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
140.7 ms | 1003 KiB | 18 Q