How to understand the grammatical rules of this sentence?

WBOY
Release: 2016-08-04 09:20:57
Original
938 people have browsed it

<code>    <?php
        foreach($hobby as $v){
            echo "<input type='checkbox' name='hobby[]' value='".$v."'/>".$v;
        }
    ?></code>
Copy after login
Copy after login

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

Reply content:

<code>    <?php
        foreach($hobby as $v){
            echo "<input type='checkbox' name='hobby[]' value='".$v."'/>".$v;
        }
    ?></code>
Copy after login
Copy after login

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.

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!