我应该使用IF还是ELSE IF进行第二次陈述


Should I use IF or ELSE IF for the second statment

我无法执行此代码,我确信我写错了。有人能帮忙吗?你看到什么不对吗?

if ($value1!=$value OR $value2 !=$value ) {
  echo "something ";
  exit();
}
else if ($value3!=$value OR $value4 !=$value) {
  echo "something";
  exit(); 
}

不清楚您要做什么——变量和变量名称之间的比较并不直观也就是说,这里不需要else

如果不希望在满足if语句时执行else(或elseif)块中的代码,则只需要else(或elseif)。这里,if块包含exit()。因此,当满足if条件时,将不再执行任何代码,无论它是在if块中还是在elseif块中。


更多详细信息:

以下是ifelse的工作原理:

if (condition) {
    // do this if condition is true
} elseif (condition_2) {
    // do this if condition is false but condition_2 is true
} else {
    // do this if neither condition nor condition_2 is true
}
/*
 * code here will execute whether or not either condition or condition_2 is true
 */

在您的代码中,如果if中的条件为true,则会短路if块之后的所有内容。也就是说,如果是$value1!=$value OR $value2 !=$value,则在调用exit();时脚本将退出。