<?php
// Data
$name = ['Mazda','Mazda','Lexus', 'Lexus'];
$count = [1,1,1,1];
$gp =[54,35,23,46];
// declare result array
$result = [];
for($i = 0; $i < count($name); $i++) {
$result[ $name[$i] ] = [
"C" => ($result[ $name[$i] ]['C'] ?? 0) + $count[$i],
"GP" => ($result[ $name[$i] ]['GP'] ?? 0) + $gp[$i]
];
}
print_r($result);
preferences:
24.77 ms | 404 KiB | 5 Q