PHP如果功能有多个结果

时间:2018-01-17 13:53:55

标签: php xml if-statement logic

我正在尝试根据所在的部门为属性返回不同的状态。有Sales和Lettings部门,每个部门都有一个表示该属性状态的数字系统。

我尝试使用if函数来查询每个属性的部门和状态,并为每个状态返回不同的文本字符串,但所有属性都标记为“保持”(即第一个选项)< / p>

代码如下。道歉并不是特别优雅。

function prop_status( $dept = null, $availability = null) {
if ( $dept = "Lettings" and $availability = "1") {
  return "On hold";
}
if ( $dept = "Lettings" and $availability = "2") {
  return "For rent";
}
if ( $dept = "Lettings" and $availability = "3") {
  return "References pending";
}
if ( $dept = "Lettings" and $availability = "4") {
  return "Let agreed";
}
if ( $dept = "Lettings" and $availability = "5") {
  return "Let";
}
if ( $dept = "Sales" and $availability = "1") {
  return "On hold";
}
if ( $dept = "Sales" and $availability = "2") {
  return "For sale";
}
if ( $dept = "Sales" and $availability = "3") {
  return "Under offer";
}
if ( $dept = "Sales" and $availability = "4") {
  return "Sold STC";
}
if ( $dept = "Sales" and $availability = "5") {
  return "Sold";
}
if ( $dept = "Sales" and $availability = "7") {
  return "Withdrawn";
}

非常感谢任何帮助实现这项工作。

1 个答案:

答案 0 :(得分:0)

您应该将所有=更改为==

function prop_status( $dept = null, $availability = null) {
if ( $dept == "Lettings" and $availability == "1") {
  return "On hold";
}
if ( $dept == "Lettings" and $availability == "2") {
  return "For rent";
}
if ( $dept == "Lettings" and $availability == "3") {
  return "References pending";
}
if ( $dept == "Lettings" and $availability == "4") {
  return "Let agreed";
}
if ( $dept == "Lettings" and $availability == "5") {
  return "Let";
}
if ( $dept == "Sales" and $availability == "1") {
  return "On hold";
}
if ( $dept == "Sales" and $availability == "2") {
  return "For sale";
}
if ( $dept == "Sales" and $availability == "3") {
  return "Under offer";
}
if ( $dept == "Sales" and $availability == "4") {
  return "Sold STC";
}
if ( $dept == "Sales" and $availability == "5") {
  return "Sold";
}
if ( $dept == "Sales" and $availability == "7") {
  return "Withdrawn";
}

请参阅php here

中的比较运算符

$a == $b如果$ a等于$ b

,则返回TRUE

$a === $b如果$ a等于$ b,则返回TRUE,并且它们属于同一类型。