Php two-layer foreach loop how to set the initial value of the in-layer loop variable to 0 $ Question):?>
$ Answer):?>
How to enable the $ I value to start from 0 after the second layer loop after the layer loop, instead of continuing the value of the previous loop
Reply to discussion (solution)
I don't understand what you mean, for example. Or how you want to output it.
I don't understand what you mean, for example. Or how you want to output it.
The requirement is this. the following several options are related to one-to-many options. I wrote two foreach loop data that can be read,
For example, in question 1, the following option is 1. option a 2. option B Question 2 the following option is 1. option c 2. option d I want to use $ I for the option number here, but the option number of question 2 after two foreach starts from 3.
$question): ?>
-
.
-
I don't understand what you mean, for example. Or how you want to output it.
The requirement is this. the following several options are related to one-to-many options. I wrote two foreach loop data that can be read,
For example, in question 1, the following option is 1. option a 2. option B Question 2 the following option is 1. option c 2. option d I want to use $ I for the option number here, but the option number of question 2 after two foreach starts from 3.
'; $ Questions = array ('Issue 1', 'issue 2', 'issue 3'); $ answers = array ('option ', '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
Option2 option B
Q2
Option1 option c
Option2 option d
Q3
Option1 option e
Option2 option f
#3 code
Change row 8th
Change row 14th
Each time the inner layer traverses the $ answers array, and takes only a small amount of data.
We recommend that you adjust the data organization method (reference #4)
Of course, you can also perform clustering on $ answers before the main loop starts.