Page 1 of 1

Array within a loop

Posted: Mon Jul 28, 2008 11:11 am
by aceconcepts
Hi,

How can I add to an array without creating a nested array?

Here is my loop currently:

Code: Select all

 
for($x=0; $x<count($questionSelect); $x++)
{
    $questionRow=mysql_fetch_array(getQuestion($companyId, $questionSelect[$x]));
                                
    $_SESSION['selectedStageQuestionsText'][]=array($questionSelect[$x]=>$questionRow['strQuestionText']);
}
 
The above outputs the array like so: Array ( [0] => Array ( [59] => Will you be travelling with your partner? ) )

I basically want to get rid of the "holding array" Array([0]=>...) how can i add to the array without having to create as a nested array?

Thanks.

Re: Array within a loop

Posted: Mon Jul 28, 2008 11:42 am
by ghurtado
I think you may want to change

Code: Select all

 
  $_SESSION['selectedStageQuestionsText'][]=array($questionSelect[$x]=>$questionRow['strQuestionText']);
 
to

Code: Select all

 
  $_SESSION['selectedStageQuestionsText'][$questionSelect[$x]] = $questionRow['strQuestionText'];
 
(if I understood your question correctly)

Re: Array within a loop

Posted: Tue Jul 29, 2008 3:18 am
by aceconcepts
Nice one. That did the trick.