在&#34中使用多个变量;如果"声明

时间:2013-06-22 10:23:31

标签: php variables if-statement

我有一些像这样的变量:

$elm = $_GET['elm']; 
$elm_nm = $_GET['elm_nm']; 
$tag = $_GET['tag']; 

这样的一些PHP代码:

if (!empty($elm)) {

foreach($html->find($elm, $elm_nm) as $d) {
 echo $d->outertext;
}  

} else { 

echo "noop";

}

我想在if语句中有多个var,所以我尝试了:

if (!empty($elm, $elm_nm, $tag)) {

if (!empty($elm . $elm_nm . $tag)) {

还有一些其他的东西,但Dreamweaver在这一行上给了我错误。我该怎么写得好呢?

3 个答案:

答案 0 :(得分:1)

试试这个

if ( !empty($elm) &&  !empty($elm_nm) &&  !empty($tag) ) {..}

答案 1 :(得分:1)

只需将其与&&

结合使用即可

像这样:

if (!empty($elm) && !empty($elm_nm) && !empty($tag)) {

答案 2 :(得分:1)

这将检查您的所有参数。

$something_is_empty = false;   // set our flag to false

foreach($_GET as $a_parameter) // this will create a loop for every element in GET array
{                              // and the variable $a_parameter will get the value of one GET element each time.
                               // this way we will scan every element of GET array

   if(isempty($a_parameter))   // if something is empty, raise the flag
       $something_is_empty=true; 
}

if($something_is_empty) // if flag is raised, something was empty
{
    echo "noop";
}
else // if flag was not raised, EVERY element in GET array WAS NOT EMPTY
{
    echo "everything has a value!";
}