PHP AND OR使用if else条件

dev*_*234 0 php logic if-statement

我有一个困惑,这里有什么不对?如果设置A&B或C,则应打印是,否则应打印错误消息

$a = 1;
$b = 2;
$c = null;

if ((is_null($a) && is_null($b)) || is_null($c)) {
    echo 'A and B or C cannot be blank.';
}
else
    echo 'yes';
Run Code Online (Sandbox Code Playgroud)

在这里,我已经分配了A&B但仍然打印'A和B或C不能为空白.'

为了更清楚.A =名字,B =姓名,C =电子邮件.因此,用户应该提供名字和姓氏,否则请发送电子邮件.

Al *_*yan 5

你应该这样做:

$a = 1;
$b = 2;
$c = null;

if ((!is_null($a) && !is_null($b)) || !is_null($c)) {
    echo 'yes';
}
else
{
    echo 'A and B or C cannot be blank.';
}
Run Code Online (Sandbox Code Playgroud)

更新:

if ((is_null($a) || is_null($b)) && is_null($c)) {
    echo 'A and B or C cannot be blank.';
}
Run Code Online (Sandbox Code Playgroud)