0

I have a foreach below that when print_r or var_dumped it shows the correct data but once I put the $finalMenuDetails into the location I need it shows Array and not the list.

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/>';
}       

Process:

$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;
    }
7
  • Can you show the print_r or var_dump result of your arrays, as well as your desired output? Somewhere you are concatenating an array object into your string instead of a value within the array. Commented Jul 28, 2014 at 21:09
  • 4
    perhaps you want $finalMenuDetails .= Commented Jul 28, 2014 at 21:12
  • @Cory Done I am wanting Item 1 23 etc Commented Jul 28, 2014 at 21:13
  • @Dagon I have done the .= and I am still getting Array Commented Jul 28, 2014 at 21:21
  • you are echoing $finalMenuDetails and not $menuDetailsItem ? Commented Jul 28, 2014 at 21:28

1 Answer 1

1

Try something like this:

$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);

OUTPUT

item 1 23
item 2 90
item 3 23
Sign up to request clarification or add additional context in comments.

11 Comments

The final result is going into an email how can I make it so that I can print it but now show it on the final page?
Are you trying to maintain the form while sending it through email?
Correct thats what I am trying to do
U can maintain the line breaks by using nl2br()
You need to replace : "<strong>Items:</strong><br/><br/>".print_r($menuResult) . "\n" with just "<strong>Items:</strong><br/><br/>".$menuResult . "\n"
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.