Tried adding&andorin the same if but the or condition doesn't work
else if ($usuario = 12 & $banca <=3 or =>7){ echo "ok"; }
is only valid when$banca <=3
, but is invalid when$banca >=7
What's wrong?
The range I'm trying to check is between <=3 和 >=7
There are some problems with your code. A simpler one and a more complex one: syntax and operator precedence.
First of all, operator
=
is used for assignment, not comparison. Therefore, the result of$usuario = 12
is12
. Next, you have a bitwise operator&
that outputs0
if$banca > 3
, otherwise12
. Finally, you take the result and check if it is>= 7
. In other words: using them without knowing the operator won't do you any good. Please delve into the php language.Although your syntax works in PHP, operator precedence can also mess up the results. Check out PHP'soperator precedence. This is one reason why linters and best practices manuals will instruct you to add parentheses to make your criteria clear, rather than relying onobscureoperator precedence.
Now, how do we solve this problem? Again, please take a closer look at PHP's operators and their syntax. There are some good courses out there, as well as theOfficial PHP Manual. But don't leave you hanging, your situation should look like this: