3v4l.org

run code in 300+ PHP versions simultaneously
<?php $inventory = array( array("fruit"=>"orange", "price"=>3), array("fruit"=>"kiwi", "price"=>2), array("fruit"=>"apple", "price"=>3), array("fruit"=>"apple", "price"=>3), array("fruit"=>"apple", "price"=>3), array("fruit"=>"orange", "price"=>4), array("fruit"=>"banana", "price"=>10), array("fruit"=>"banana", "price"=>10), ); function groupFruits(&$result, $item) { $key = $item['fruit']; @$result[$key] += $item['price']; return $result; } $grouped = array_reduce($inventory, 'groupFruits', array()); arsort($grouped); print_r($grouped);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EuCmT
function name:  (null)
number of ops:  14
compiled vars:  !0 = $inventory, !1 = $grouped
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   24     1        INIT_FCALL                                               'array_reduce'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 'groupFruits'
          4        SEND_VAL                                                 <array>
          5        DO_ICALL                                         $3      
          6        ASSIGN                                                   !1, $3
   26     7        INIT_FCALL                                               'arsort'
          8        SEND_REF                                                 !1
          9        DO_ICALL                                                 
   28    10        INIT_FCALL                                               'print_r'
         11        SEND_VAR                                                 !1
         12        DO_ICALL                                                 
         13      > RETURN                                                   1

Function groupfruits:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EuCmT
function name:  groupFruits
number of ops:  11
compiled vars:  !0 = $result, !1 = $item, !2 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   18     2        FETCH_DIM_R                                      ~3      !1, 'fruit'
          3        ASSIGN                                                   !2, ~3
   19     4        BEGIN_SILENCE                                    ~5      
          5        FETCH_DIM_R                                      ~7      !1, 'price'
          6        ASSIGN_DIM_OP                +=               1          !0, !2
          7        OP_DATA                                                  ~7
          8        END_SILENCE                                              ~5
   21     9      > RETURN                                                   !0
   22    10*     > RETURN                                                   null

End of function groupfruits

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.57 ms | 1395 KiB | 19 Q