How to submit multiple form elements having the same name in PHP
1 03 2005In 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];
Recent Comments