我有一個像下面一樣的嵌套數組。當用戶提交時更新總價格陣列
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;}
問題是,我該如何更新總每當一個正確的折扣代碼的用戶密鑰並提交表單,從而使總價格將總是最新的,因爲現在沒有做到這一點。
您需要在某處存儲該值。平面文件,數據庫等 – andrewb
@andrewb我可以將它存儲在會話中嗎? –
用戶會話?當用戶註銷/離開時將被破壞。解釋你的要求。 – andrewb