3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = array( 0 =>array('driver'=>'xxxx', 'distance' => 100, 'vehicle' => 1, 'date' => '2019-10'), 1=>array('driver'=>'xxxx', 'distance' => 200, 'vehicle' => 2, 'date' => '2019-10'), 2=>array('driver'=>'yyyy', 'distance' => 100, 'vehicle' => 3, 'date' => '2019-10')); $result = []; foreach($array as $v){ $key = $v["driver"] . "_" . $v["date"]; if(isset($result[$key])){ $result[$key]["distance"] += $v["distance"]; }else{ $result[$key] = $v; } } print_r($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 19
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 19
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 16
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
filename:       /in/rfoNV
function name:  (null)
number of ops:  24
compiled vars:  !0 = $array, !1 = $result, !2 = $v, !3 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   18     1        ASSIGN                                                   !1, <array>
   19     2      > FE_RESET_R                                       $6      !0, ->19
          3    > > FE_FETCH_R                                               $6, !2, ->19
   20     4    >   FETCH_DIM_R                                      ~7      !2, 'driver'
          5        CONCAT                                           ~8      ~7, '_'
          6        FETCH_DIM_R                                      ~9      !2, 'date'
          7        CONCAT                                           ~10     ~8, ~9
          8        ASSIGN                                                   !3, ~10
   21     9        ISSET_ISEMPTY_DIM_OBJ                         0          !1, !3
         10      > JMPZ                                                     ~12, ->16
   22    11    >   FETCH_DIM_R                                      ~15     !2, 'distance'
         12        FETCH_DIM_RW                                     $13     !1, !3
         13        ASSIGN_DIM_OP                +=               1          $13, 'distance'
         14        OP_DATA                                                  ~15
   21    15      > JMP                                                      ->18
   24    16    >   ASSIGN_DIM                                               !1, !3
         17        OP_DATA                                                  !2
   19    18    > > JMP                                                      ->3
         19    >   FE_FREE                                                  $6
   28    20        INIT_FCALL                                               'print_r'
         21        SEND_VAR                                                 !1
         22        DO_ICALL                                                 
         23      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
135.73 ms | 1000 KiB | 14 Q