Check ahead in array
Posted: Fri Mar 03, 2006 5:05 am
I'm posting in the hope that whilst typing this out the solution will come to me as it usually does. Rest assured I will be working on this after I have posted and won't just sit here waiting for an answer!
I have an array of arrays. e.g
The second element in the array denotes whether a question is a sub question (true) or the start of a new block of questions (false).
Say I want to display 3 main questions at a time. I will want to display all the subquestions that go with it.
In my head the logic is something like this:
My main headache is how to look forward for the subquestions infinitely until it finds the next question that isn't.
I think it may involve a while loop and next() but I'm not sure and I'm feeling like a complete noob again all of a sudden.
Must have taken too many blows to the head whilst snowboarding last week
Will continue to experiment in the meantime....
I have an array of arrays. e.g
Code: Select all
$qlist = array(
array("What is your name?", "false"),
array("What is your age?", "true"),
array("What is your hair colour", "true"),
array("What is your favourite food?", "false"),
array("Do you like cheese", "true"),
array("Do you have a tv?", "false"),
array("Do you drink?", "false"),
...............etc
)Say I want to display 3 main questions at a time. I will want to display all the subquestions that go with it.
In my head the logic is something like this:
Code: Select all
start a loop
echo the first question
look at the next question in the array to see if it is a subquestion
if yes:
echo the subquestion
look at the next question in the array to see if it is a subquestion
if yes:
echo the subquestion
look at the next question in the array to see if it is a subquestion etc etc
if no:
next loop until 3 main questions have been displayedI think it may involve a while loop and next() but I'm not sure and I'm feeling like a complete noob again all of a sudden.
Must have taken too many blows to the head whilst snowboarding last week
Will continue to experiment in the meantime....