3v4l.org

run code in 300+ PHP versions simultaneously
<?php $firstArr = 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')); print_r($firstArr); $finalArray= array(); foreach($firstArr as $arr){ if(!isset($finalArray[$arr['driver']])){ $finalArray[$arr['driver']] = $arr; }else{ $finalArray[$arr['driver']]['distance']= $finalArray[$arr['driver']]['distance']+$arr['distance']; $finalArray[$arr['driver']]['vehicle']= $finalArray[$arr['driver']]['vehicle'].','.$arr['vehicle']; } } print_r(array_values($finalArray));
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 35
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 35
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 15
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 35
filename:       /in/S8hdn
function name:  (null)
number of ops:  43
compiled vars:  !0 = $firstArr, !1 = $finalArray, !2 = $arr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   17     1        INIT_FCALL                                               'print_r'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                                 
   19     4        ASSIGN                                                   !1, <array>
   21     5      > FE_RESET_R                                       $6      !0, ->35
          6    > > FE_FETCH_R                                               $6, !2, ->35
   23     7    >   FETCH_DIM_R                                      ~7      !2, 'driver'
          8        ISSET_ISEMPTY_DIM_OBJ                         0  ~8      !1, ~7
          9        BOOL_NOT                                         ~9      ~8
         10      > JMPZ                                                     ~9, ->15
   25    11    >   FETCH_DIM_R                                      ~10     !2, 'driver'
         12        ASSIGN_DIM                                               !1, ~10
         13        OP_DATA                                                  !2
         14      > JMP                                                      ->34
   27    15    >   FETCH_DIM_R                                      ~12     !2, 'driver'
         16        FETCH_DIM_R                                      ~15     !2, 'driver'
         17        FETCH_DIM_R                                      ~16     !1, ~15
         18        FETCH_DIM_R                                      ~17     ~16, 'distance'
         19        FETCH_DIM_R                                      ~18     !2, 'distance'
         20        ADD                                              ~19     ~17, ~18
         21        FETCH_DIM_W                                      $13     !1, ~12
         22        ASSIGN_DIM                                               $13, 'distance'
         23        OP_DATA                                                  ~19
   28    24        FETCH_DIM_R                                      ~20     !2, 'driver'
         25        FETCH_DIM_R                                      ~23     !2, 'driver'
         26        FETCH_DIM_R                                      ~24     !1, ~23
         27        FETCH_DIM_R                                      ~25     ~24, 'vehicle'
         28        CONCAT                                           ~26     ~25, '%2C'
         29        FETCH_DIM_R                                      ~27     !2, 'vehicle'
         30        CONCAT                                           ~28     ~26, ~27
         31        FETCH_DIM_W                                      $21     !1, ~20
         32        ASSIGN_DIM                                               $21, 'vehicle'
         33        OP_DATA                                                  ~28
   21    34    > > JMP                                                      ->6
         35    >   FE_FREE                                                  $6
   32    36        INIT_FCALL                                               'print_r'
         37        INIT_FCALL                                               'array_values'
         38        SEND_VAR                                                 !1
         39        DO_ICALL                                         $29     
         40        SEND_VAR                                                 $29
         41        DO_ICALL                                                 
         42      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
144.03 ms | 1405 KiB | 17 Q