I am looping through a series of inputs and saving their values to an array. Each element in the array is a special class that has a name (so it can be uniquely identified) and an answer (initialized as null, populated in the following loop):
class Question
{
public name;
public answer;
}
...
foreach ($quiz_questions as $q)
{
$inputName = $q->name;
$response = $_POST[$inputName];
$q->answer = $response;
print_r($q->answer);
}
print_r($quiz_questions);
When I print each individual answer during the iteration, the values come out correctly, but when I print the entire array after the loop, the answer components are NULL like they were before the loop.
Any idea what the problem is?
foreach ($quiz_questions as &$q)