I have a form which posts 2 fields as arrays.
Here are the fields as they appear in the form:
Code: Select all
<input type="text" name="seqQuestionNumber[]" class="numberInput" />
<input type="hidden" name="seqQuestionLocation[]" value="'.$key.'-'.$stage.'-'.$qKey.'" class="hidden" />
I use the following to attempt to add each "seqQuestionNumber" as a nested array:
Code: Select all
for($x=0; $x < count($seqQuestionNumber); $x++)
{
$seqArray[]=array($seqQuestionLocation[$x]=>$seqQuestionNumber[$x]);
}
//ADD THE QUESTION NUMBERS TO THE CORRECT LOCATION IN $_SESSION['selectedStageQuestions']
//LOOP $seqArray
foreach($seqArray as $key=>$location)
{
foreach($key as $qKey=>$number)
{
//GET EACH KEY FROM THE ARRAY ($key, $stageKey, $questionKey)
$exp=explode("-", $location);
$expKey=$exp[0];
$expStage=$exp[1];
$expQuestionKey=$exp[2];
//ADD QUESTION NUMBERS TO $_SESSION['selectedStageQuestions']
$_SESSION['selectedStageQuestions'][$expKey][$expStage][$expQuestionKey][]=array($expQuestionKey=>$number);
}
}