數組值我有兩個餅乾,它們的值是這樣的:總和兩個PHP
foreach($_COOKIE as $key=>$val) {
$piece = explode(",", $val);
$t_cost = array($piece[3]);
print_r($t_cost); //It prints Array ([0] => 11) Array ([0] => 11)
echo $total_cost = array_sum($t_cost);
}
但它打印只有一個值。我怎樣才能添加這兩個值來總結它們?
按每個值( $ t_cost)在一個新的數組,然後應用數組 - 總和該數組? –