$question):?>
$answer):?>
How to allow the value of $i to start at 0 instead of the value of the last loop after the second inner loop after the inner loop is completed
Reply to discussion (solution)
I don't understand what you mean, for example. or explain how you want to output it.
I don't understand what you mean, for example. or explain how you want to output it.
The requirement is such a problem the following several options questions are a one-to-many relationship with options I wrote two foreach loop data to read,
For example, question 1 The following option is 1. Option a 2. Option B question 2 The following option is 1. Option C 2. Option d The title of the option here I want to do with $i, but two foreach after question 2 is the number of the option that starts with 3
$question):?>
-
-
.
-
-
I don't understand what you mean, for example. or explain how you want to output it.
The requirement is such a problem the following several options questions are a one-to-many relationship with options I wrote two foreach loop data to read,
For example, question 1 The following option is 1. Option a 2. Option B question 2 The following option is 1. Option C 2. Option d The title of the option here I want to do with $i, but two foreach after question 2 is the number of the option that starts with 3
'; $questions = array ( ' problem 1 ', ' question 2 ', ' question 3 '); $answers = Array ( ' option A ', ' option B '), array (' option C ', ' Option d '), array (' option e ', ' option F '), foreach ($questions as $k = + $question) { echo ' Q '. $k + 1). '
'; foreach ($answers [$k] as $i = = $answer) { echo ' option '. $i + 1). ' '. $answer. '
'; } Echo '
';}? >
Q1
Option1 Option A
Option2 Option B
Q2
Option1 option C
Option2 option D
Q3
Option1 option E
Option2 option F
#3 Code
The 8th line should read
The 14th line should read
The inner layer iterates through the $answers array each time, and takes only a small amount of data
It's not worth the candle, it is recommended to adjust the data organization method (see # #)
Of course, you can cluster the $answers before the main loop starts.