我有一个带有嵌套数组的数组,如下所示。
cart (
[total] => 98
[itemcount] => 3
[items] => Array ( [0] => 0 [1] => 3 [2] => 5 )
[itemprices] => Array ( [0] => 33.00 [3] => 32.00 [5] => 33 )
[itemqtys] => Array ( [0] => 1 [3] => 1 [5] => 1 )
[iteminfo] => Array ( [0] => Chemistry [3] => Additional Mathematics [5] => Physics )
)
当用户输入正确的折扣代码时,我在开关中有下面的代码,此功能将触发。我可以让它显示折扣价。
$anewvalue = 16.50;
$physubject = "Physics";
$index = array_search($physubject , $cart->iteminfo);
if (false !== $index) {
$cart->itemprices[$index] = $anewvalue;}
问题是,每当用户输入正确的折扣代码并提交表单时,我如何更新总价,以便总价始终是最新的,因为现在它不会这样做。