My PHP Code is:
$userAnswers = array( // you would get these values via $_POST["answers"]
"s1" => array(
"q1" => $_POST['S1Q1'],
"q2" => $_POST['S1Q2']
),
"s2" => array(
"q1" => $_POST['S2Q1'],
"q2" => $_POST['S2Q2'],
"q3" => $_POST['S2Q3'],
"q4" => $_POST['S2Q4']
),
"s3" => array(
"q1" => $_POST['S3Q1'],
"q2" => $_POST['S3Q2'],
"q3" => $_POST['S3Q3'],
"q4" => $_POST['S3Q4'],
"q5" => $_POST['S3Q5']
),
);
$q001 = $_POST['S1Q1'];
$q002 = $_POST['S1Q2'];
$q003 = $_POST['S2Q1'];
$q004 = $_POST['S2Q2'];
$q005 = $_POST['S2Q3'];
$q006 = $_POST['S2Q4'];
$q007 = $_POST['S3Q1'];
$q008 = $_POST['S3Q2'];
$q009 = $_POST['S3Q3'];
$q010 = $_POST['S3Q4'];
$q011 = $_POST['S3Q5'];
$savearray = array($q001, $q002, $q003, $q004, $q005, $q006, $q007, $q008, $q009, $q010, $q011);
$_SESSION['annual'] = $savearray;
I think It will be too tedious and time consuming if I have a lot of questions and I am entering the POST twice and was thinking of how to replace the second appearance of $_POST[]
with something like the following:
$userAnswers[$s][$q]
Will that go in order starting from $q001
and forward? This way the $_POST[]
is called only once.
So something like this:
$q001 = $userAnswers[$s][$q];
$q002 = $userAnswers[$s][$q];
$q003 = $userAnswers[$s][$q];
$q004 = $userAnswers[$s][$q];
$q005 = $userAnswers[$s][$q];
$q006 = $userAnswers[$s][$q];
$q007 = $userAnswers[$s][$q];
$q008 = $userAnswers[$s][$q];
$q009 = $userAnswers[$s][$q];
$q010 = $userAnswers[$s][$q];
$q011 = $userAnswers[$s][$q];
Thinking I might have to use a foreach
statement?
foreach () { }