在if函数中收集所有(都是真的)

时间:2015-04-11 06:52:57

标签: php

我在条件函数中准备了一些变量。

<?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函数中的所有内容(哪些是真的)。

我希望有人能理解我在这里要做的事情。并提前感谢您的帮助。

1 个答案:

答案 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