2014-02-05 23 views
0

我有這個循環,它將電子郵件地址放在$sendmail變量中。php將分離的變量賦值給包含許多值的變量

<?php do { ?>  
<?php 
$sendmail .= $row_Recordset2['companyemail'].","." "; 
?> 
<?php } while ($row_Recordset2 =mysql_fetch_assoc($Recordset2)); ?> 

,如果我打印變量: <?php echo $sendmail; ?>

返回一些電子郵件地址,如: [email protected][email protected][email protected]

如何我可以把這個郵件中的變量,例如:

[email protected] [email protected] [email protected]

+2

你不能,你不應該。陣列是爲此而發明的。看那個單詞。 –

回答

0

要使用數組做到這一點通過@NB的建議:

<?php do { ?>  
<?php 
$sendmail[] = $row_Recordset2['companyemail']; 
?> 
<?php } while ($row_Recordset2 =mysql_fetch_assoc($Recordset2)); ?> 

將其打印出來:

print_r($sendmail); 

訪問個人電郵:

echo $sendmail[0]; 
echo $sendmail[1]; 

0
<?php 
while ($row_Recordset2 = mysql_fetch_assoc($Recordset2)) { 
$sendmail = $row_Recordset2['companyemail']; 
echo $sendmail; 
} 
?>