PHP POST Form Inputs – Multidimensional Arrays

In PHP it is common to have form inputs with the same name. Many times these will be generated dynamically (i.e. a WordPress Repeatable Custom Meta Field). PHP stores these values to the POST Superglobal as a multidimensional array. To begin with, run this example script here PHP Form Inputs Example.

Let’s say you have a text input for streets. You simply add brackets at the end of the name:

<input type="text" name="street[]">

When you submit the form as a POST value, you will be able to view the values as a multidimensional array starting at 0 (i.e. $_POST[‘street’][0], $_POST[‘street’][1], etc.).

To view the code of the example on GitHub click here.

Published by burnedfaceless

Brian Abbott is studying IT and Music Composition at Georgia Southern University.

Leave a comment

Your email address will not be published. Required fields are marked *