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);
It’d be up to you to define
$stepand the$ANSWERnvariables, 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
foreachto give you the$stepvariable)