3v4l.org

run code in 300+ PHP versions simultaneously
<?php $payments = [ ['bookingId' => 1, 'vendorId' => 3, 'amount' => 50], ['bookingId' => 1, 'vendorId' => 3, 'amount' => 85], ['bookingId' => 1, 'vendorId' => 4, 'amount' => 14], ]; $result = array_reduce( $payments, function(array $carry, array $payment): array { $carry[$payment['vendorId']] = $payment; $carry[$payment['vendorId']]['amount'] = ($carry[$payment['vendorId']]['amount'] ?? 0) + $payment['amount']; return $carry; }, [] ); var_dump(array_values($result));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/CZCHv
function name:  (null)
number of ops:  15
compiled vars:  !0 = $payments, !1 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    9     1        INIT_FCALL                                               'array_reduce'
   10     2        SEND_VAR                                                 !0
   11     3        DECLARE_LAMBDA_FUNCTION                          ~3      [0]
   15     4        SEND_VAL                                                 ~3
   16     5        SEND_VAL                                                 <array>
    9     6        DO_ICALL                                         $4      
          7        ASSIGN                                                   !1, $4
   19     8        INIT_FCALL                                               'var_dump'
          9        INIT_FCALL                                               'array_values'
         10        SEND_VAR                                                 !1
         11        DO_ICALL                                         $6      
         12        SEND_VAR                                                 $6
         13        DO_ICALL                                                 
         14      > 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/CZCHv
function name:  {closure}
number of ops:  20
compiled vars:  !0 = $carry, !1 = $payment
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   12     2        FETCH_DIM_R                                      ~2      !1, 'vendorId'
          3        ASSIGN_DIM                                               !0, ~2
          4        OP_DATA                                                  !1
   13     5        FETCH_DIM_R                                      ~4      !1, 'vendorId'
          6        FETCH_DIM_R                                      ~7      !1, 'vendorId'
          7        FETCH_DIM_IS                                     ~8      !0, ~7
          8        FETCH_DIM_IS                                     ~9      ~8, 'amount'
          9        COALESCE                                         ~10     ~9
         10        QM_ASSIGN                                        ~10     0
         11        FETCH_DIM_R                                      ~11     !1, 'amount'
         12        ADD                                              ~12     ~10, ~11
         13        FETCH_DIM_W                                      $5      !0, ~4
         14        ASSIGN_DIM                                               $5, 'amount'
         15        OP_DATA                                                  ~12
   14    16        VERIFY_RETURN_TYPE                                       !0
         17      > RETURN                                                   !0
   15    18*       VERIFY_RETURN_TYPE                                       
         19*     > RETURN                                                   null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
123.89 ms | 1013 KiB | 16 Q