I'd like to have a form's data arrive on the server ordered in a specific format as an array. Presently, I have the following form elements which may appear numerous times in my markup:
...
<tr>
<td><p>Friend's Name:</p></td>
<td><p><input type="text" name="friends[name][]" /></p></td>
<td><p>Friend's Email:</p></td>
<td><p><input type="text" name="friends[email][]" /></p></td>
<td><p><input type="button" value="+" class="addOne" /></td>
</tr>
...
When submitted, the result appears like this:
[friends] => Array
(
[name] => Array
(
[0] => John Doe
[1] => Jane Doe
)
[email] => Array
(
[0] => [email protected]
[1] => [email protected]
)
)
I can use this array just fine, but I'm curious if it's possible to have the same data appear in the form of the following array example:
[friends] => Array
(
[0] => Array
(
[name] => John Doe
[email] => [email protected]
)
[1] => Array
(
[name] => Jane Doe
[email] => [email protected]
)
)
I understand that I could use the names with specific indexes to acheive this, like this:
friends[0][name]
and friends[0][email]
But I'm curious if I can achieve the same result without having to dynamically write new names for the form elements.