Excuse me, but I have no idea what this is called, so I’ll try and explain it.
With HTML forms you can have input fields of the same name, with auto assigning keys for each one, for example:
<form action="somepage" method="post">
<input type="text" name="phone[]" />
<input type="text" name="phone[]" />
<input type="submit" />
</form>
when this form is submitted, the server receives the data in via POST.
as an associative array it looks like this:
Array(
[phone] => Array ( [0] => 123456789 [1] => 987654321 )
)
where keys 0,1 are given automatically.
how would you do the same with radio fields?
<input type="radio" name="option[]"/>
<input type="radio" name="option[]"/>
is treating both fields as one (as it should) and not giving it unique keys…
As far as HTML is concerned, fields with the same name are just fields with the same name. Radio buttons are a special case in that sharing a name makes them part of a group and only one may be selected.
In most form handling libraries, you can get data from multiple elements with the same name presented as an array.
In PHP, you can only get the data presented as an array if the name ends with
[](or[something]for arrays with predefined indexes).Only checked radio buttons can be successful and only one radio button in a group can be checked (that is the point of radio buttons).
If you want the user to pick multiple options, use checkboxes. If you give those checkboxes the same name and end it with
[]then PHP will get all the values of the checked checkboxes in a single array.