3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arrays = [ ['id' => 1, 'name' => '', 'cat_name' => 'Food & Beverage', 'quantity' => 1, 'price' => 25, 'image' => 'books_image/calories_fat_carbohydrate.png'], ['id' => 2, 'name' => '', 'cat_name' => 'Food & Beverage', 'quantity' => 5, 'price' => 38, 'image' => 'books_image/the_law_relating_to_food.png'], ['id' => 3, 'name' => '', 'cat_name' => 'Food & Beverage', 'quantity' => 5, 'price' => 19, 'image' => 'books_image/it_starts_with_food.png'], ['id' => 1, 'name' => '', 'cat_name' => 'Food & Beverage', 'quantity' => 2, 'price' => 19, 'image' => 'books_image/it_starts_with_food.png'] ]; $result = array_values(array_reduce($arrays, function($result, $entry) { if (isset($result[$entry['id']])) { $result[$entry['id']]['quantity'] += $entry['quantity']; } else { $result[$entry['id']] = $entry; } return $result; }, [])); var_dump($result);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iNDfb
function name:  (null)
number of ops:  15
compiled vars:  !0 = $arrays, !1 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   17     1        INIT_FCALL                                               'array_values'
          2        INIT_FCALL                                               'array_reduce'
          3        SEND_VAR                                                 !0
          4        DECLARE_LAMBDA_FUNCTION                          ~3      [0]
   25     5        SEND_VAL                                                 ~3
          6        SEND_VAL                                                 <array>
   17     7        DO_ICALL                                         $4      
   25     8        SEND_VAR                                                 $4
   17     9        DO_ICALL                                         $5      
         10        ASSIGN                                                   !1, $5
   27    11        INIT_FCALL                                               'var_dump'
         12        SEND_VAR                                                 !1
         13        DO_ICALL                                                 
         14      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 11
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iNDfb
function name:  {closure}
number of ops:  16
compiled vars:  !0 = $result, !1 = $entry
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   18     2        FETCH_DIM_R                                      ~2      !1, 'id'
          3        ISSET_ISEMPTY_DIM_OBJ                         0          !0, ~2
          4      > JMPZ                                                     ~3, ->11
   19     5    >   FETCH_DIM_R                                      ~4      !1, 'id'
          6        FETCH_DIM_R                                      ~7      !1, 'quantity'
          7        FETCH_DIM_RW                                     $5      !0, ~4
          8        ASSIGN_DIM_OP                +=               1          $5, 'quantity'
          9        OP_DATA                                                  ~7
   18    10      > JMP                                                      ->14
   22    11    >   FETCH_DIM_R                                      ~8      !1, 'id'
         12        ASSIGN_DIM                                               !0, ~8
         13        OP_DATA                                                  !1
   24    14    > > RETURN                                                   !0
   25    15*     > RETURN                                                   null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.65 ms | 1008 KiB | 16 Q