1

配列があり、それを文字列と連結したいと思います。

これは配列です:

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
) 

これは私のコードです:

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>");
    }
}

$ bodyの値がこのようになる可能性はありますか?

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
4

2 に答える 2

5

join / implodeを使用して、配列を文字列に変換できます。

join("\r\n", $arrs)
于 2012-06-22T09:29:47.890 に答える
1

配列が$arrayに格納されている場合は、以下のコードを試してください。

<?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;
?>
于 2012-06-22T09:31:14.243 に答える