Q:

PHP Harvest Arrays Posted From Form

I have a form that is posting an array of values for each input and there are four related inputs that I need to harvest in the controller. Here's the form:
<div data-role="collapsible" data-theme="a" data-content-theme="d" data-collapsed-icon="arrow-d" data-expanded-icon="arrow-u">
    <h4>Resident Contact<br>(Phone and/or Door to Door)</h4>
    <div id="resident_contact" data-role="fieldcontain">
        <div id="contact_entry">
            <p style="font:bold 10px sans-serif">Name/Apt</p>
            <input type="text" name="contact_name[]" /><br>
            <p style="font:bold 10px sans-serif">Personal Interaction</p>
            <input type="text" name="contact_interaction[]" /><br>
            <p style="font:bold 10px sans-serif">Updated Contact Info</p>
            <input type="text" name="contact_updated_info[]" /><br>
            <p style="font:bold 10px sans-serif">Work Orders Questions Concerns</p>
            <input type="text" name="contact_work_orders[]" />
            <br><br>
        </div>
    </div>
    <p><a href="#" data-role="button" data-mini="true" data-inline="true" data-icon="plus" data-theme="b" id="btnContact">Add Another</a></p>
 </div>

A dump of the POST variable looks like this:
[contact_name] => Array ( [0] => Joan Rivers / 999 [1] => John Adams / 125 ) [contact_interaction] => Array ( [0] => At Desk [1] => At Desk ) [contact_updated_info] => Array ( [0] => No [1] => No ) [contact_work_orders] => Array ( [0] => Asked for more coffee filters [1] => Requested a new remote )

In my form handler, how do I turn that into an associative array where the contact_name, contact_interaction, contact_updated_info and contact_work_orders are group together properly and all of them (since the user can add up to 10 such data groups) inside a PHP array called $contacts?

A:

You can make PHP create the array in the format you want by changing the names of the input fields.
Instead of
<input type="text" name="contact_name[]" />
<input type="text" name="contact_interaction[]" />

Try this:
<input type="text" name="contact[name][]" />
<input type="text" name="contact[interaction][]" />

This will create $_POST['contact'] and it will be an associative array.

