哪个if语句更有效? [关闭]

Which if statement below is more efficient in PHP:

$A=@"llaweikj";
$B=@"aesrwh";
$C=@"uymy";
$D=@"xcvb";

if ( ($A==$B) && ($C==$D) ) {
    //Do something with it
}

OR

if ($A==$B) {
    if ($C==$D) {
       //Do something with it
    }
}

What would be more efficient?

In your question, Both statements are different.

In first statement:

if ( ($A==$B) && ($C==$D) )

First it will check if A is equals to B and C is equals to D then the code will execute within the if statement. Means both condition needs to be true.

But in your second statement:

if ($A==$B) 
if ($C==$D)

the code inside the true condition will execute if A is equals to B then first if condition will execute and if if C is equals to D then second statement will execute. In case of both are true then both if condition will execute.

EDITED:

After updating your question, the answer is here:

Your first condition if ( ($A==$B) && ($C==$D) ) is more efficient. In second statement there is unnecessary if, even though you can check both condition with in single if condition. so your first condition will execute fast.

The two examples are (now) logically equivalent, and since Php does short circuit boolean evaluation, in your first example, the second condition C==D would only be evaluated if the first A == B was true, which is equivalent to the explicitly nested second example.

The choice of which is more efficient now depends on what else you may want to do with the 2 conditions. The first check is fine in an all or nothing scenario:

if ( ($A==$B) && ($C==$D) ) {
    // Both are true
}
else {
    // Here we only know that at least one condition failed 
    // we would need to recheck if additional logic was required
}

Whereas the nested ifs allow for more efficient detection of all the different permutations of the two conditions, in a scenario where finer grained logic is required:

if ($A==$B) {
    if ($C==$D) {
     // $A == $B and $C == $D
   }
   else {
     // $A == $B but $C != $D
   }
}
else {
    // $A != $B 
    // ... we may again need to check $C vs $D
}