let's say I have something like this:
if(1 == 0 && do_stuff()) {
...
}
Obviously 1 is not 0, so there's no point to check the other condition. So does PHP ever run do_stuff()
?
PHP Conditional Statements if statement - executes some code if one condition is true. if...else statement - executes some code if a condition is true and another code if that condition is false. if... elseif...else statement - executes different codes for more than two conditions.
<? php if (argument) { // end if statement } else if (different argument) { // end if statement } else if (another different argument) { // end if statement } else { // do something } ?>
The if/else statement With the if statement, a program will execute the true code block or do nothing. With the if/else statement, the program will execute either the true code block or the false code block so something is always executed with an if/else statement.
We can use if statements inside if statements. These statements are called Nested If Statements.
No - PHP uses lazy evaluation (sometimes called short-circuit evaluation), so if the first condition in a logical AND is false, it won't attempt to evaluate any of the other conditions.
Likewise, if you were doing an OR and the first condition was true it wouldn't evaluate the second.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With