<code> <?php foreach($hobby as $v){ echo "<input type='checkbox' name='hobby[]' value='".$v."'/>".$v; } ?></code>
This is a fragment of a check box, hobby[] is an array, what are the syntax rules for this? How to understand it? Doesn't creating an array require array? Thank you
<code> <?php foreach($hobby as $v){ echo "<input type='checkbox' name='hobby[]' value='".$v."'/>".$v; } ?></code>
This is a fragment of a check box, hobby[] is an array, what are the syntax rules for this? How to understand it? Doesn't creating an array require an array? Thank you
The foreach()
function of PHP is used to traverse the entire array. foreach($hobby as $v)
is to obtain each item (denoted as $v) in the array $hobby[] in sequence.
This is not creating an array but traversing each item in the array $hobby[] and outputting it as a checkbox value.
For example, the length of $hobby[] is 5, this code will output a total of 5 checkboxes, and the value of each checkbox corresponds to an item in the array.