在会话阵列PHP更新值 [英] Update value in session array php

查看:106
本文介绍了在会话阵列PHP更新值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对session数组的问题。

I have question about the SESSION array.

我只是在不同的会话中添加项目和数量。我用code是这样的:

I just add item and qty in different session. I use code like this :

$_SESSION['idproduct'] = $id.",";
$_SESSION['qtyproduct'] = $qty.",";

我已经写了条件,使会议的价值会是这样,如果我们增加3项:

I have write the condition so the value of session will be like this if we add 3 item :

$_session['idproduct'] = 1,4,6,
$_session['qtyproduct'] = 3,4,5,

我的问题是如何更新量,如果我有拿到身份证?

my question is how to update quantity if i have get the id ?

推荐答案

它们存储阵列,这样你可以使用ID作为关键字访问量:

Store them as arrays, that way you can access the quantity using the ID as a key:

$_SESSION['quantity'][$id] = $quantity;

因此​​,而不是存储您的ID和数量两个独立的字符串,你让他们在一个阵列中,与ID为关键。转换阵列上面的例子是这样的:

So instead of storing your ID and Quantity in two separate strings, you have them in one array, with the ID as the key. Converting your example above your array will look like this:

array(
    1    => 3
    4    => 4
    6    => 5
);

然后,如果你想添加/调整你刚才设置的$ id $量任何适当的值并使用上面的行。

Then if you wanted to add / adjust anything you just set $id and $quantity to the appropriate values and use the line above.

这篇关于在会话阵列PHP更新值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆