3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = [ [ "menu_id" => 7, "menu_name" => "Kasagbutan Meals", "menu_price" => "100.00", "qty" => "1", "special_instructions" => "" ], [ "menu_id" => 7, "special_instructions" => "", "menu_name" => "Kasagbutan Meals", "menu_price" => "100.00", "qty" => "1", ], [ "menu_id" => 6, "menu_name" => "Coke", "menu_price" => "50.00", "qty" => "1", "special_instructions" => "" ] ]; $exclude = array_flip(['qty']); $totals = array_reduce($arr, function($totals, $item) use ($exclude) { $id = array_diff_key($item, $exclude); ksort($id); $hash = crc32(json_encode($id)); if (array_key_exists($hash, $totals)) { $totals[$hash]['qty'] += $item['qty']; } else { $totals[$hash] = $item; } return $totals; }, []); print_r($totals);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YDsfc
function name:  (null)
number of ops:  17
compiled vars:  !0 = $arr, !1 = $exclude, !2 = $totals
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   28     1        INIT_FCALL                                               'array_flip'
          2        SEND_VAL                                                 <array>
          3        DO_ICALL                                         $4      
          4        ASSIGN                                                   !1, $4
   30     5        INIT_FCALL                                               'array_reduce'
          6        SEND_VAR                                                 !0
          7        DECLARE_LAMBDA_FUNCTION                          ~6      [0]
          8        BIND_LEXICAL                                             ~6, !1
   40     9        SEND_VAL                                                 ~6
         10        SEND_VAL                                                 <array>
   30    11        DO_ICALL                                         $7      
         12        ASSIGN                                                   !2, $7
   42    13        INIT_FCALL                                               'print_r'
         14        SEND_VAR                                                 !2
         15        DO_ICALL                                                 
         16      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 25
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YDsfc
function name:  {closure}
number of ops:  29
compiled vars:  !0 = $totals, !1 = $item, !2 = $exclude, !3 = $id, !4 = $hash
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        BIND_STATIC                                              !2
   31     3        INIT_FCALL                                               'array_diff_key'
          4        SEND_VAR                                                 !1
          5        SEND_VAR                                                 !2
          6        DO_ICALL                                         $5      
          7        ASSIGN                                                   !3, $5
   32     8        INIT_FCALL                                               'ksort'
          9        SEND_REF                                                 !3
         10        DO_ICALL                                                 
   33    11        INIT_FCALL                                               'crc32'
         12        INIT_FCALL                                               'json_encode'
         13        SEND_VAR                                                 !3
         14        DO_ICALL                                         $8      
         15        SEND_VAR                                                 $8
         16        DO_ICALL                                         $9      
         17        ASSIGN                                                   !4, $9
   34    18        ARRAY_KEY_EXISTS                                         !4, !0
         19      > JMPZ                                                     ~11, ->25
   35    20    >   FETCH_DIM_R                                      ~14     !1, 'qty'
         21        FETCH_DIM_RW                                     $12     !0, !4
         22        ASSIGN_DIM_OP                +=               1          $12, 'qty'
         23        OP_DATA                                                  ~14
   34    24      > JMP                                                      ->27
   37    25    >   ASSIGN_DIM                                               !0, !4
         26        OP_DATA                                                  !1
   39    27    > > RETURN                                                   !0
   40    28*     > RETURN                                                   null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
138.61 ms | 1009 KiB | 20 Q