数组作为会话变量 [英] Array as session variable

查看:45
本文介绍了数组作为会话变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在 PHP 中将数组设为会话变量?

Is it possible to make an array a session variable in PHP?

情况是我有一个表格(第 1 页),其中一些单元格具有指向特定页面的链接.下一页将有一个名称列表(第 2 页,我想将其保留在会话数组中)及其各自的复选框.在提交此表单时,它将导致一个交易页面(第 3 页,其中已发布复选框的值保存在数据库中以获取相应名称).现在,如果我返回第一页并单击另一个单元格,会话数组将包含新的名称列表还是旧的名称列表?

The situation is that I have a table (page 1) with some cells having a link to a particular page. The next page will have a list of names (page 2, which I want to keep in a session array) with their respective checkboxes. On submitting this form, it will lead to a transaction page (page 3, where values of posted checkboxes are kept in a database for corresponding names). Now, if I return to the first page and click another cell, will the session array contain the new list of names or the old ones?

推荐答案

是的,PHP 支持数组作为会话变量.请参阅此页面 例如.

Yes, PHP supports arrays as session variables. See this page for an example.

至于您的第二个问题:一旦您设置了会话变量,它将保持不变,直到您更改它或 取消设置.因此,如果第 3 页不更改会话变量,它将保持不变,直到第 2 页再次更改为止.

As for your second question: once you set the session variable, it will remain the same until you either change it or unset it. So if the 3rd page doesn't change the session variable, it will stay the same until the 2nd page changes it again.

这篇关于数组作为会话变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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