search

Home  >  Q&A  >  body text

javascript - The principle of passing an array to php when the name of the form object is xx[]

<form method="post" action="arrayformdata.php">
<label>Tags</label>
<input type="text" name="tags[]" />
<input type="text" name="tags[]"/>
<input type="text" name="tags[]"/>
< input type="text" name="tags[]"/>
<input type="text" name="tags[]"/>
<input type="submit" value= "submit">
</form>
</html>

In this way, you can get all the values ​​named tags[] through $_POST['tags'] in php and merge them into an array.
I don’t understand how it works

迷茫迷茫2822 days ago362

reply all(3)I'll reply

  • 天蓬老师

    天蓬老师2017-05-16 13:09:31

    When submitting, you can see that the requested form information is

    tags[]: 111
    tags[]: 222

    When PHP receives this information, it will pass the variables into the current script in the form of an associative array. Since it is an associative array, there will be keys, and the tags[] above are the same set of keys. PHP will put them into an array when processing.

    reply
    0
  • 巴扎黑

    巴扎黑2017-05-16 13:09:31

    $array=[];
    for($i=0;$i<100;$i++){
        $array[]=$i;
    }
    print_r($array);

    I think it should be the same as this. It's because the PHP side does the processing (I don't know about other back-end languages). Because what was sent to the front desk is like this, as shown in the picture

    reply
    0
  • 某草草

    某草草2017-05-16 13:09:31

    Same meaning as above, all input boxes submitted are assigned to $_POST, $_POST is a super global variable, so it can be received anywhere

    reply
    0
  • Cancelreply