以编程方式构建关联数组
我目前正在构建一个跨越多个步骤(页面)的调查问卷系统。我正在使用存储在会话中的关联数组来存储提交的答案。
我无法理解如何以编程方式构建它。
该数组应如下所示,
array(STEP => array(ANSWER 1, ANSWER 2, ANSWER 3, etc...));
我将步骤作为变量“$step”,并将答案数组构建为单独的“$answers”变量。
所以基本上我需要能够建立的是以下内容
array($step => $answers);
I am currently building a questionnaire system which spans over multiple steps (pages). I am using an assoc array which is stored in session to store the submitted answers.
I am having problems getting my head around how I would build this up programmatically.
The array should be as follows
array(STEP => array(ANSWER 1, ANSWER 2, ANSWER 3, etc...));
I have the step as a variable '$step' and the answer array is built up as a separate '$answers' variable.
So basically what I need to be able to build up is the following
array($step => $answers);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当然,您可以定义
$step
和$ANSWERn
变量。并正确初始化您的会话。完成调查问卷后,您只需单步遍历数组即可提取所有答案:(
编辑:我稍微修改了
foreach
来为您提供$step
变量)It'd be up to you to define
$step
and the$ANSWERn
variables, of course. And properly initializing your session, too.After the questionnaire, you'd just step through your array to extract all the answers:
(edit: I slightly modified the
foreach
to give you the$step
variable)