我在下面有一个foreach,当print_r
或var_dumped
显示正确的数据时,但是一旦我将$finalMenuDetails
放入我需要的位置,它就会显示Array
而不是清单。
的var_dump
array(3) {
[0]=>
string(6) "Item 1"
[1]=>
string(6) "item 2"
[2]=>
string(6) "item 3"
}
array(3) {
[0]=>
string(2) "23"
[1]=>
string(2) "90"
[2]=>
string(2) "23"
}
PHP
foreach($menuDetailsItem as $key => $value)
{
$finalMenuDetails[] = $value. " ".$amount[$key] . '<br/>';
}
过程:
$menuName = $_POST['menu'];
$menuDetailsItem = $_POST['item'];
$menuDetailsItemAmount = $_POST['amount'];
$menuResult = '';
foreach ($menuDetailsItem as $key => $value) {
$menuResult .= $value." ".$menuDetailsItemAmount[$key]."<br/>";
}
if(empty($errorMessage))
{
$to = "";
$subject = "Booking";
$headers = "From: " . strip_tags($_POST['Email']) . "\r\n" . "Reply-To: ". strip_tags($_POST['Email']) . "\r\n" . "Content-Type: text/html; charset=ISO-8859-1\r\n" . //header("Location: http://redherringcatering.co.nz/Thankyou.html");
$message = "\n" . "<strong>NAME:</strong> ". $varName . "<br />" . "<br />" . "<strong>CONTACT:</strong> " . $varContact . "<br />" . "<br />" . "<strong>EMAIL:</strong> ". $varEmail . "<br />" . "<br />" ."<strong>COMPANY:</strong> ". $varCompany . "<br />" . "<br />" . "<strong>No. ATTENDING:</strong> ".$varAttending . "<br />" . "<br />" ."<strong>FUNCTION DATE:</strong> ". $varFunction . "<br />" . "<br />" ."<strong>FUNCTION DAY:</strong> ". $varFunctionDay . "<br />" . "<br />" ."<strong>DATE ORDERED:</strong> ". $varOrdered . "<br />" . "<br />" ."<strong>TIME REQUIRED:</strong> ". $varTime . "<br />" . "<br />" . "<strong>ONSITE:</strong> ". $varOnsite . ", ". $varOnsite2 . "<br />" . "<br />" ."<strong>INVOICE TO:</strong> ". $varInvoice . "<br />" . "<br />" ."<strong>ADDRESS:</strong>\n". $varAddress . "<br />" . "<br />" ."<strong>SPECIAL NEEDS:</strong> ". $varSpecial . "<br />" . "<br />" . "<strong>ORDER DETAILS:</strong><br/><br/>". $menuName . "<br/>"."<br/>"."<strong>Items:</strong><br/><br/>".print_r($menuResult) . "\n";
mail($to,$subject,$message,$headers);
exit;
}
答案 0 :(得分:1)
尝试这样的事情:
$item = array("item 1","item 2","item 3") ;
$amount = array("23","90","23") ;
$result_array = '';
foreach ($item as $key => $value) {
$result_array .= $value." ".$amount[$key]."<br/>";
}
print_r($result_array);
<强>输出强>
item 1 23
item 2 90
item 3 23