Reputation: 201
I have a php form that allows the user to add multiple copies of three fields (installed item, description, and quantity). The results of each field are captured in an array.
I am sending the results via an email form. Currently I have it set to the following:
$email_body = "Date: $date \n".
"Installed Items: \n" . implode("\n", $_POST['installed']) . "\n" .
"Installed Description: \n" . implode("\n", $_POST['installed-description']) . "\n" .
"Installed Quantity: \n" . implode("\n", $_POST['installed-quantity']) . "\n";
It displays like this in the email:
Installed Items:
Item 1
Item 2
Item 3
Installed Description:
Description 1
Description 2
Description 3
Installed Quantity:
Quantity 1
Quantity 2
Quantity 3
I would like for it to display as follows:
Item 1
Description 1
Quantity 1
Item 2
Description 2
Quantity 2
etc...
Any help would be appreciated (and, I'm pretty new to PHP so pardon the noob-ness of this question).
Upvotes: 2
Views: 92
Reputation: 10356
In this case I would recommend to use a for
loop:
for($i = 0; $i < COUNT($_POST['installed']);$i++)
{
$msg .= 'Item '.$i.'\n';
$msg .= $_POST['installed'][$i].'\n';
$msg .= $_POST['installed-description'][$i].'\n';
$msg .= $_POST['installed-quantity'][$i].'\n';
$msg .= '\n'; //extra space between the items
}
Upvotes: 1