Surprisingly to many, the above code will output bool(true)
seeming to imply that the and
operator is behaving instead as an or
.
The issue here is that the =
operator takes precedence over the and
operator in order of operations, so the statement $x = true and false
ends up being functionally equivalent to:
$x = true; // sets $x equal to true
true and false; // results in false, but has no affect on anything
This is, incidentally, a great example of why using parentheses to clearly specify your intent is generally a good practice, in any language. For example, if the above statement $x = true and false
were replaced with $x = (true and false)
, then $x
would be set to false
as expected.
If you want to explore more, visit our PHP edu & tutorials section! Below are some examples:
Another week to bring you the top yield platforms for three of the most prominent…
If you hold a large volume of LEDU tokens above 1 million units and wish…
It’s another week and like always we have to explore the top yield platforms for…
At a time where we’re constantly seeking tools and strategies to simplify our crypto investments,…
As we kick off another week, it's time to explore the top yield platforms for…
We're excited to share that Education Ecosystem was recently featured in an article on Business…