2012-06-22 94 views
0

我有一個數組,我想將它與一個字符串連接起來。concat字符串和數組在php中

這是數組:

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

是有可能,$體的價值會是這樣?

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 
+0

你應該使用array_push(),然後爆()試試這個 – Yang

+1

很有可能......那你試試? – BugFinder

回答

1

如果數組存儲在$數組,那麼試試下面的代碼:

<?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; 
?>