3v4l.org

run code in 300+ PHP versions simultaneously
<?php $a1 = Array ( 0 => (object) array ( 'time' => '03:00 PM - 04:30 PM', 'booked' => 3, ), 1 => (object ) array ( 'time' => '05:00 PM - 06:30 PM', 'booked' => 2 ) ); $a2 = Array ( '0' => (Object) array ( 'time' => '03:00 PM - 04:30 PM', 'booked' => 3 ), '1' => (Object) array ( 'time' => '07:00 PM - 08:30 PM', 'booked' => 1 ) ); $a3 = array_merge($a1,$a2); $r = []; $keys = ['booked','booked_slotes']; foreach($a3 as $v){ array_key_exists($v->time, $r) ? ($r[$v->time]->booked += $v->booked) : ($r[$v->time] = $v); } print_r(array_values($r));
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 18, Position 2 = 35
Branch analysis from position: 18
2 jumps found. (Code = 78) Position 1 = 19, Position 2 = 35
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 29
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 35
filename:       /in/JAZ4d
function name:  (null)
number of ops:  43
compiled vars:  !0 = $a1, !1 = $a2, !2 = $a3, !3 = $r, !4 = $keys, !5 = $v
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   CAST                                          8  ~6      <array>
          1        INIT_ARRAY                                       ~7      ~6, 0
   12     2        CAST                                          8  ~8      <array>
          3        ADD_ARRAY_ELEMENT                                ~7      ~8, 1
    2     4        ASSIGN                                                   !0, ~7
   20     5        CAST                                          8  ~10     <array>
          6        INIT_ARRAY                                       ~11     ~10, 0
   26     7        CAST                                          8  ~12     <array>
          8        ADD_ARRAY_ELEMENT                                ~11     ~12, 1
   16     9        ASSIGN                                                   !1, ~11
   30    10        INIT_FCALL                                               'array_merge'
         11        SEND_VAR                                                 !0
         12        SEND_VAR                                                 !1
         13        DO_ICALL                                         $14     
         14        ASSIGN                                                   !2, $14
   31    15        ASSIGN                                                   !3, <array>
   32    16        ASSIGN                                                   !4, <array>
   33    17      > FE_RESET_R                                       $18     !2, ->35
         18    > > FE_FETCH_R                                               $18, !5, ->35
   34    19    >   FETCH_OBJ_R                                      ~19     !5, 'time'
         20        ARRAY_KEY_EXISTS                                         ~19, !3
         21      > JMPZ                                                     ~20, ->29
   36    22    >   FETCH_OBJ_R                                      ~21     !5, 'time'
         23        FETCH_OBJ_R                                      ~24     !5, 'booked'
         24        FETCH_DIM_RW                                     $22     !3, ~21
         25        ASSIGN_OBJ_OP                                 1  ~23     $22, 'booked'
         26        OP_DATA                                                  ~24
         27        QM_ASSIGN                                        ~25     ~23
         28      > JMP                                                      ->33
   38    29    >   FETCH_OBJ_R                                      ~26     !5, 'time'
         30        ASSIGN_DIM                                       ~27     !3, ~26
         31        OP_DATA                                                  !5
         32        QM_ASSIGN                                        ~25     ~27
         33    >   FREE                                                     ~25
   33    34      > JMP                                                      ->18
         35    >   FE_FREE                                                  $18
   41    36        INIT_FCALL                                               'print_r'
         37        INIT_FCALL                                               'array_values'
         38        SEND_VAR                                                 !3
         39        DO_ICALL                                         $28     
         40        SEND_VAR                                                 $28
         41        DO_ICALL                                                 
         42      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
137.43 ms | 1007 KiB | 16 Q