我有以下给定的数组
Array
(
[0] => 2,3
[1] => 2,3
)
我想总结并获得变量的结果。例如。变量a = 4 (2+2=4)
和变量b = 6 (3+3=6)
。我在php编码。
答案 0 :(得分:0)
试试这个
$a = 0;
$b =0;
foreach ($yourArr as $temp)
{
$a += $temp[0];
$b += $temp[1];
}
echo "a = ".$a."<br>";
echo "b = ".$b;
<强>输出强>
a = 4
b = 6
答案 1 :(得分:0)
在foreach中使用EXPLODE
<?php
$yourArr = array('2,3','2,3');
$a = 0;
$b =0;
foreach ($yourArr as $temp)
{
$tempnew = explode(",",$temp);
$a += $tempnew[0];
$b += $tempnew[1];
}
echo "a = ".$a."<br>";
echo "b = ".$b;
?>