03-02-2012, 11:20 AM
[eluser]CroNiX[/eluser]
If your array looks exactly what you stated, you could do this, where $t is your original array:
This will create an array like you showed you wanted no matter how many additions to your form there are, assuming each new section is comprised of the 'room_types', 'room_types_sr', 'max_occupancy' and 'extra_bedding' fields.
If your array looks exactly what you stated, you could do this, where $t is your original array:
Code:
// get the keys for room_types. It should be the same as all other fields
// since they will be equal in number for each array of form values
$keys = array_keys($t['room_types']);
// for storing newly formatted data
$insert_data = array();
// loop through the keys (happens to be 3 with your sample data)
// and assign data to a new array based on the key
foreach($keys as $key)
{
$insert_data[] = array(
'room_types' => $t['room_types'][$key],
'room_types_sr' => $t['room_types_sr'][$key],
'max_occupancy' => $t['max_occupancy'][$key],
'extra_bedding' => $t['extra_bedding'][$key]
);
}
// get the action the form
$action = $t['insert_room_types']; //will be 'Insert' from your example