Creating an Array with PHP

html, php

Solution

I've assumed you're using `POST`.

You would use

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

Then on the post page, you could use:

foreach($_POST['interest'] as $i){
    echo $i. "<br>";
}

or whichever method you wanted to use to get the `POST` data.

You could also do something like:

<input type="text" name="interest[music]"/>
<input type="text" name="interest[food]"/>

You can then call this data by using:

<?php echo $_POST['interest']['music']; ?>

Problem

I have a form with multiple text inputs that all have the same name. How would I process that with my PHP when the user submits the form? HTML: ``` <input type="text" name="interest"/> ```

Original source