I have a mulit demensional array like this ...
** note the array has closing brackets which is not shown in this image. so theres no issue in the syntax.
I want to add the values in each key (Openness, Conscientiousness) together so that i have a array like :
Array{
[Openness]=> Array(
[0] => 16
)
[Conscientiousness]=>Array (
[0]=> 10
)
}
When i tried this code after looking through existing questions :
$sumArray = array();
foreach ($finalarr as $k=>$subArray) {
foreach ($subArray as $id=>$value) {
//$sumArray[$id]+=$value;
array_key_exists( $id, $sumArray ) ? $sumArray[$id] += $value : $sumArray[$id] = $value;
}
}
print_r($sumArray);
I get :
which is not what i want. ANy ideas how to fix the array?


array_sum()$sumArrayshould be$k, not$id.