3v4l.org

run code in 300+ PHP versions simultaneously
<?php $a = Array ( '0' => Array ( 'id' => 34, 'building_id' => 786, 'tenancy_rate' => 0, 'rent_per_room' => 10000, 'management_fee_per_room' => 0 ), '1' => Array ( 'id' => 35, 'building_id' => 786, 'tenancy_rate' => 10, 'rent_per_room' => 11810, 'management_fee_per_room' => 5400, 'rent' => 86050 ), '2' => Array ( 'id' => 36, 'building_id' => 786, 'tenancy_rate' => 20, 'rent_per_room' => 11810, 'management_fee_per_room' => 5400, 'rent' => 86050 ), '3' => Array ( 'id' => 56, 'building_id' => 798, 'tenancy_rate' => 0, 'rent_per_room' => 10000, 'management_fee_per_room' => 5400, 'rent' => 77000 ), '4' => Array ( 'id' => 57, 'building_id' => 798, 'tenancy_rate' => 10, 'rent_per_room' => 11810, 'management_fee_per_room' => 5400, 'rent' => 86050 ), '5' => Array ( 'id' => 58, 'building_id' => 798, 'tenancy_rate' => 20, 'rent_per_room' => 11810, 'management_fee_per_room' => 5400, 'rent' => 86050 ) ); $f = []; foreach($a as $v){ if(!empty($f[$v['tenancy_rate']])){ $f[$v['tenancy_rate']]['rent'] += $v['rent']; }else{ $f[$v['tenancy_rate']] = [ 'tenancy_rate' => $v['tenancy_rate'], 'rent' => isset($v['rent']) ? $v['rent'] : 0 ]; } } print_r($f);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 27
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 27
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 14
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 22
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
filename:       /in/nWRGA
function name:  (null)
number of ops:  32
compiled vars:  !0 = $a, !1 = $f, !2 = $v
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
   63     1        ASSIGN                                                   !1, <array>
   64     2      > FE_RESET_R                                       $5      !0, ->27
          3    > > FE_FETCH_R                                               $5, !2, ->27
   65     4    >   FETCH_DIM_R                                      ~6      !2, 'tenancy_rate'
          5        ISSET_ISEMPTY_DIM_OBJ                         1  ~7      !1, ~6
          6        BOOL_NOT                                         ~8      ~7
          7      > JMPZ                                                     ~8, ->14
   66     8    >   FETCH_DIM_R                                      ~9      !2, 'tenancy_rate'
          9        FETCH_DIM_R                                      ~12     !2, 'rent'
         10        FETCH_DIM_RW                                     $10     !1, ~9
         11        ASSIGN_DIM_OP                +=               1          $10, 'rent'
         12        OP_DATA                                                  ~12
   65    13      > JMP                                                      ->26
   68    14    >   FETCH_DIM_R                                      ~13     !2, 'tenancy_rate'
   69    15        FETCH_DIM_R                                      ~15     !2, 'tenancy_rate'
         16        INIT_ARRAY                                       ~16     ~15, 'tenancy_rate'
   70    17        ISSET_ISEMPTY_DIM_OBJ                         0          !2, 'rent'
         18      > JMPZ                                                     ~17, ->22
         19    >   FETCH_DIM_R                                      ~18     !2, 'rent'
         20        QM_ASSIGN                                        ~19     ~18
         21      > JMP                                                      ->23
         22    >   QM_ASSIGN                                        ~19     0
         23    >   ADD_ARRAY_ELEMENT                                ~16     ~19, 'rent'
   68    24        ASSIGN_DIM                                               !1, ~13
   70    25        OP_DATA                                                  ~16
   64    26    > > JMP                                                      ->3
         27    >   FE_FREE                                                  $5
   74    28        INIT_FCALL                                               'print_r'
         29        SEND_VAR                                                 !1
         30        DO_ICALL                                                 
         31      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.84 ms | 1003 KiB | 14 Q