2013-10-01 52 views
-1

我正在嘗試打印一個項目列表,並在其旁邊的數量的計算。到目前爲止,只有數量被打印在圖像旁邊。我需要這個值(即蘋果)出現。該值確實出現,直到我添加「數量」。任何幫助將不勝感激。打印文字和PHP變量

echo "<br/><br/><br/> You are leaving on ". $_POST["departuredate"]."</p>"; 
echo "You are returning on ". $_POST["returndate"]."</p>"; 

$return= strtotime($_POST["returndate"]); 
$depart = strtotime($_POST["departuredate"]); 
$datediff = $return - $depart; 
echo "You are going for <b> "; 
$quantity=floor($datediff/(60*60*24)); 
echo $quantity; 
echo " days"; 


$Yoghurt= 'Yoghurt' + $quantity; 
$Apple = 'Apple' + $quantity; 
$Banana = 'Banana' + $quantity; 


.... 


$FoodList=array_unique($FoodList); 
$img_path = 'empty_checkbox.gif'; 

if(!empty($FoodList)) 
{ 
    foreach ($FoodList as $key => $value) 
    { 
     echo "<li>" . "<img src='$img_path' />" . " ". $value ."</li>"; 
    } 
    echo "</ul>"; 
} 
+0

從哪裏'$ FoodList'來? – DontVoteMeDown

+0

'$ Yoghurt ='Yoghurt'+ $ quantity;''+'來自JavaScript。它必須是'.' – iCode

回答

2

使用.到Concat的變量爲一個字符串,不++是數學加法運算符。 PHP將字符串轉換爲1並將其添加到$quantity

$Yoghurt= 'Yoghurt' . $quantity; 
$Apple = 'Apple' . $quantity; 
$Banana = 'Banana' . $quantity; 

有關更詳細的信息,請參見string operators

0

在PHP中,您不使用+來加入(連接字符串),您應該使用.來代替。