A
A
Alexander Lashchevsky2015-11-22 03:20:16
PHP
Alexander Lashchevsky, 2015-11-22 03:20:16

How does if/else work in php?

There are two variables $firstand $second, containing the values 0​​or 1.

if ( $first OR $second ) {
   // Условие выполняется
} else {
   // Условие не выполняется
}

Common sense (and Google results, by the way, too) tells me that the condition is met EITHER if $first == 1, and $second == 0, or vice versa.
But practice shows that the condition is met even if both variables are equal to one. Those. is executed, not when STRICTLY one of them is equal to one, but IF AT LEAST one.
What's the catch?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DevMan, 2015-11-22
@Alexanevsky

no catch: 1 or 1 = 1 , i.e. true .
if you need to strictly check, then use and or xor .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question