How to submit multiple form elements having the same name in PHP

1 03 2005

In PHP, it is possible to have multiple form elements having the same name. However, the element’s name must be appended with “[]“. For example:

<input type=”text” name=”hoho[]” value=”first element” /><br />
<input type=”text” name=”hoho[]” value=”second element” /><br />
<input type=”text” name=”hoho[]” value=”third element” /><br />

At the processing PHP, the values of the submitted element can be retrieved as an array via:

$myarray = $_POST['hoho']; // Note that the name does not end with “[]” when retrieving
echo $myarray[0];
echo $myarray[1];
echo $myarray[2];


Actions

Information

Leave a comment

You can use these tags : <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>