一个if循环中有多个isset查询


Multiple isset queries in one if loop

我正在尝试获取以下查询:
如果存在A的值和b的值,或者如果有A的值,或如果有b的值---->做点什么

if((isset($_POST['A'], $_POST['B'])) OR !empty($_POST['B']) OR !empty($_POST['A']))
    {
        echo "there is something:" . $_POST['B'] . ", " . $_POST['A'];
    }
    else
    {
        echo "its empty<br />";
    }

当其中一个字段中有一个值时,它可以正常工作,但当两个字段都为空时,仍然可以明显看出存在某种东西。

葡萄酒可以和自动完成吗?

$checkVIN1 = mysql_query("SELECT vhl_vin FROM vhldescription");
$num_rows = mysql_num_rows($checkVIN1);
$i = 0;
echo "<script>$(function() {var availableTags = [";
while($checkVIN2 = mysql_fetch_array($checkVIN1, MYSQL_ASSOC))  {   $i++;   echo "'"" . <br />$checkVIN2['vhl_vin'] . "'",";
    if ($i == ($num_rows))  {   echo "'"" . $checkVIN2['vhl_vin'] . "'"";   }   }
echo "];$( '"#tags'" ).autocomplete({source: availableTags});});</script>";
<input id="tags" name="A" class="le-input">

这个怎么样?

<?php
$a;
$b;

if((isset($a) or isset($b)) and !(empty($a) or empty($b))){
    echo "do something";    
}else{
    echo "do nothing";
}

尝试将您的代码更改为:

$postVars = array('A', 'B');
$things = array();
foreach($postVars as $postVar) {
    if( isset($_POST[$postVar]) && !empty($_POST[$postVar]) )
    {
        $things []= $_POST[$postVar];
    }
}
if( empty($things) ) {
    echo "it's empty<br />";
} else {
    echo "there is something: "
         . join(', ', array_map(function($str) {
                                    return htmlspecialchars($str, ENT_NOQUOTES, 'UTF-8');        
                                },
                                $things)) . '.';
}