Search code examples
phphtmlcodeigniterinputbox

In php, Is it possible to create two input box with same name?


In php, i have some input boxes in a form tag

Is it possible to create two input box with same name? Is there any problem while the form is submitted?


Solution

  • Is it possible to create two input box with same name?

    Yes. Element ids must be unique, but names do not.

    Is there any problem while the form is submitted?

    PHP will discard all but the last one unless the name ends in [].

    <input name="foo[]">
    <input name="foo[]">
    

    will be accessible via

    $_POST['foo'] # an array