假设您正在尝试分配该值而不是直接输出到屏幕上:
<?php
$priceperpost = "129"; // default
if ($linecount > 100) {
$priceperpost = "Please call"; // highest price break value first
} elseif ($linecount > 30) {
$priceperpost = "89";
} elseif ($linecount > 15) {
$priceperpost = "109"; // lowest price break value last
}
?>
或者更紧凑和更灵活的东西 - 您可以将值存储在文件或数据库中并从该数据生成数组,而不必为新的价格突破值编写新的 elseif:
<?php
$priceArray = array( // insert price break values in descending order
100 => "Please call",
30 => "89",
15 => "109",
0 => "129",
);
foreach ($priceArray as $breakValue => $price) {
if ($linecount > $breakValue) {
$priceperpost = $price;
break; // found the price break, so we can exit the loop here
}
}
?>