1

HTML guarantees the order of form fields when they are encoded on submit, which means this form:

<form method="GET">
    <input name="Foo[]" value="one">
    <input name="Foo[]" value="two">
    <input name="Foo[]" value="three">
</form>

will always be encoded into this query string:

?Foo[]=one&Foo[]=two&Foo[]=three

But here's my question. When PHP pulls these values into $_GET['Foo'] does PHP guarantee the order of the array? Meaning, given that query string, will the value of Foo always equal:

array('one', 'two', 'three'); //?
4

1 回答 1

1

From the PHP Manual's FAQ on PHP and HTML:

To get your <form> result sent as an array to your PHP script you name the <input>, <select> or <textarea> elements like this:

    <input name="MyArray[]" />
    <input name="MyArray[]" />
    <input name="MyArray[]" />
    <input name="MyArray[]" />

Answer in bold:

Specifying an arrays key is optional in HTML. If you do not specify the keys, the array gets filled in the order the elements appear in the form. Our first example will contain keys 0, 1, 2 and 3.

于 2013-09-07T03:07:36.267 回答