1

I have an array, and i want to concatenate it with a string.

this is the arrays:

Array ( 
    [0] => Orange 1JD = 1
    [1] => Orange 5JD = 0
    [2] => Orange 10JD = 0
    [3] => Orange 20JD = 0
    [4] => Orange 50JD = 0
    [5] => Umniah 1JD = 0
    [6] => Umniah 5JD = 0
    [7] => Umniah 10JD = 0
    [8] => Umniah 20JD = 0
    [9] => Umniah 50JD = 0
    [10] => Zain 5JD = 0
    [11] => Zain 10JD = 0
    [12] => Zain 20JD = 0
    [13] => Zain 50JD = 0
) 

this is my code :

function emailSending($arrs){
    $to = getAdminEmail();
    $subject = "Card Quantity Alert!";
    $body = "Your Card is out of Quantity, Purchased more Card!\n\nThe Following Cards are:\n";
    foreach($arrs as &$arr){
        echo $arr;
    }
    echo $body;
    if (mail($to, $subject, $body)) {
        echo("<p>Message successfully sent!</p>");
    } else {
        echo("<p>Message delivery failed...</p>");
    }
}

is it possible that the value of $body will be like this?

Your Card is out of Quantity, Purchased more Card! The Following Cards are:
Orange 1JD = 1
Orange 5JD = 0
Orange 10JD = 0
Orange 20JD = 0
Orange 50JD = 0
Umniah 1JD = 0
Umniah 5JD = 0
Umniah 10JD = 0
Umniah 20JD = 0
Umniah 50JD = 0
Zain 5JD = 0
Zain 10JD = 0
Zain 20JD = 0
Zain 50JD = 0
2
  • you should use array_push() then implode() Try this Commented Jun 22, 2012 at 9:29
  • 1
    Very possible... what did you try? Commented Jun 22, 2012 at 9:29

2 Answers 2

5

You could use join/implode to turn the array to string.

join("\r\n", $arrs)
Sign up to request clarification or add additional context in comments.

Comments

1

If the Array is stored in $array then try the code below:

<?php
$body = 'Your Card is out of Quantity, Purchased more Card! The Following Cards are:' . "\n";

foreach ($array as $item) {
    $body .= $item . "\n";
}

print $body;
?>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.