我在条件函数中准备了一些变量。
<?php
if($one !== "")
{
$array = "Inner Join One on One.id = Number.id";
}
if($two !== "")
{
$array = "Inner Join Two on Two.id = Number.id";
}
if($three !== "")
{
$array = "Inner Join Three on Three.id = Number.id";
}
if($four !== "")
{
$array = "Inner Join Four on Four.id = Number.id";
}
?>
现在我要查看加入所需的内容。我想收集if函数中的所有内容(哪些是真的)。
我希望有人能理解我在这里要做的事情。并提前感谢您的帮助。
答案 0 :(得分:3)
尝试 -
$array = array();
if($one !== "")
{
$array[] = "Inner Join One on One.id = Number.id";
}
if($two !== "")
{
$array[] = "Inner Join Two on Two.id = Number.id";
}
if($three !== "")
{
$array[] = "Inner Join Three on Three.id = Number.id";
}
if($four !== "")
{
$array[] = "Inner Join Four on Four.id = Number.id";
}
$str = implode(" ", $array); // Can use other delimiters. here it is blankspace