Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 当使用if和else时,AND运算符的否定是什么?_Php_If Statement_Operators - Fatal编程技术网

Php 当使用if和else时,AND运算符的否定是什么?

Php 当使用if和else时,AND运算符的否定是什么?,php,if-statement,operators,Php,If Statement,Operators,我将if与&一起使用,else紧跟其后 例如: $Name = "john"; $age = "30"; 如果我这样做: if($Name =="john" && $age=="30") { some stuff } else { do other stuff } 这里的else是指:$Name=“约翰”&$age!=“30”??我对此有点困惑 谢谢&&只有在所有条件都满足时,操作员才能工作 $Name == "john"; $age == "30"; if($Name

我将
if
&
一起使用,
else
紧跟其后

例如:

$Name = "john";
$age = "30";
如果我这样做:

if($Name =="john" && $age=="30") 
{ some stuff }
else { do other stuff }
这里的else是指:
$Name=“约翰”&$age!=“30”
??我对此有点困惑


谢谢

&&只有在所有条件都满足时,操作员才能工作

$Name == "john";
$age == "30";

if($Name =="john" && $age=="30") 
{
   // Here comes only when name is john and age is 30
}
else 
{ 
  // Here comes all the time when name is not john AND age is not 30
  // If age is 30 and name is not John then comes here
  // If age is not 30 and name is John then comes here
}
if($Name =="john" && $age=="30") {// both are true}
否则条件是其中一个为假或两个都为假,如下面的条件

($Name !="john" && $age == "30")
($Name == "john" && $age != "30")
($Name != "john" && $age != "30)

您可以绘制真值表,以便更好地理解更复杂情况下的表达式:

$Name=="john" ? | $age=="30" ? | ($Name =="john" && $age=="30") 
----------------+--------------+-------------------------------
        0  (no) |      0  (no) |                     0 (false)
        0  (no) |      1 (yes) |                     0 (false)
        1 (yes) |      0  (no) |                     0 (false)
        1 (yes) |      1 (yes) |                     1  (true)

否,当
$Name=“约翰”| |$age!=“30”
。。。。“或者”、“不是”和“你也应该读@MarkBaker,这应该是这里的答案