Originally posted by coders4hire
Interesting... I'm used to vb where I would have to tell it that it's an array. In PHP, I don't have to declare that the variable $answerarray is an array?
Well, yes and no. What I said before was that you can add an existing array to the session, and as such was assuming that $answerarray already was initialized as an array.
You can take any variable, existing or not, and simply start assigning elements to it as an array. Php will allow this, and if the variable is not already an array it will become an array. This, of course, is not recommended. You would normally initialize an array before use like this
$answerarray = array();
How do I submit these results to a session array so I can pull them out in the next page. And then how can I subsequently add each page's resulting array while I loop through all the pages and questions.
Couple of ways to go about it. The most straightforward is to simply add each response to the array manually. Say you were using an associative array, using the question name as the key. You might do something like this.
$_SESSION['answers']['p2q1'] = $_POST['p2q1'];
$_SESSION['answers']['p2q2'] = $_POST['p2q2'];
$_SESSION['answers']['p2q3'] = $_POST['p2q3'];
If you had no elements in your form aside from questions, you could use array_merge to add them all at once.
$_SESSION['answers'] = array_merge($_SESSION['answers'], $_POST);
As long as you don't reassign $_SESSION['answers'] it should retain the information from previous pages. These examples are ways to add to what's there.