Felix's answer answers the question beautifully, but lacks the examples in my opinion.
This answer is prompted by the comment on Felix's answer.
can you specify keys using this method? – Qwerty Apr 27 '14 at 0:05
First off, to illustrate Felix's answer:
<input type="hidden" name="array[]" value="val1" />
<input type="hidden" name="array[]" value="val2" />
<input type="hidden" name="array[]" value="val3" />
When the request is sent to the server it will be of the type Array
.
Following is an example with keys. This will give you an array with two keys, two values each.
<input type="hidden" name="array['first']" value="val1" />
<input type="hidden" name="array['first']" value="val2" />
<input type="hidden" name="array['second']" value="val3" />
<input type="hidden" name="array['second']" value="val4" />
Finally here's an example with VueJS, which is what I was using as of this writing, which led me to this question.
<input v-for="(value, key) in data" type="hidden" :name="'array[' + key + ']'" :value="value">
I hope this will be helpful to any passersby.