2013-10-01 55 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中,您不使用+来加入(连接字符串),您应该使用.来代替。