-1

我有一些这样的变量:

$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 在这条线上给了我错误。我该如何正确地写这个?

4

3 回答 3

1

试试这个

if ( !empty($elm) &&  !empty($elm_nm) &&  !empty($tag) ) {..}
于 2013-06-22T10:26:44.057 回答
1

只需将其与 &&

像这样:

if (!empty($elm) && !empty($elm_nm) && !empty($tag)) {
于 2013-06-22T10:27:08.093 回答
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!";
}
于 2013-06-22T10:29:02.347 回答