Let’s say I have the following array and I want to add up the sub-array values using PHP:
$summary = array(
"person1" => array(
question1 => '3',
question2 => '5'),
"person2" => array(
question1 => '2',
question2 => '3'),
"person3" => array(
question1 => '1',
question2 => '2')
);
How can I output the individual array sums for each person, rather than totaling all values from all sub-arrays? For instance:
$summary = array(
"person1" => array(
questions => '8'),
"person2" => array(
questions => '5'),
"person3" => array(
questions => '3')
);
I seem to be able to add it up to 16 using a foreach loop, but what I need is individual values so I can get the highest value and lowest value.
Thanks in advance!
Loop through all people, get the sum of the questions, and place them in the same key as they came from.
Output: