PHP里如何把数组里的值相加

2024-11-23 04:19:17
推荐回答(2个)
回答(1):

//摘自php5手册模简陆
$a = array(2, 4, 6, 8);
echo "sum(a) = " . array_sum($a) . "\n"旦顷;

$b = array("a" => 1.2, "b" => 2.3, "c"咐纳 => 3.4);
echo "sum(b) = " . array_sum($b) . "\n";
?>

回答(2):

做一个简单循环就好.