我开始学习 PHP,这可能是一个简单的问题,但我没有找到解决方案 :( 我已经弄清楚如何从 $people[0] 计算总和,但我如何从所有三个数组?
$people[0] = 18。但是我如何得到 $people[0] + $people[1] + $people[2] 的总和?
<?php
$people = array(
array(
'name' => "David",
'del1' => "6",
'del2' => "5",
'del3' => "4",
'del4' => "3",
),
array(
'name' => "John",
'del1' => "7",
'del2' => "4",
'del3' => "6",
'del4' => "5",
),
array(
'name' => "Jason",
'del1' => "3",
'del2' => "6",
'del3' => "5",
'del4' => "5",
),
);
function total_sum() {
global $people;
$sum = array_sum($people[0]);
echo $people[0][name]." got ".$sum." points";
}
total_sum();
?>