-1

我正在尝试打印项目列表,并在其旁边计算数量。到目前为止,仅在图像旁边打印了数量。我也需要出现价值(即苹果)。该值确实出现了,直到我添加了“数量”。任何帮助将不胜感激。

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

2 回答 2

2

用于.将变量连接到字符串,而不是+. +是数学加法运算符。PHP 将字符串类型转换为 a1并将其添加到$quantity.

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

有关更深入的信息,请参阅字符串运算符。

于 2013-10-01T11:24:34.893 回答
0

在 PHP 中,您不使用+连接(连接字符串),而应使用.

于 2013-10-01T11:33:05.907 回答