Example:
I have a variable , which can be between 1 and 10 .
I make the comparisons / conditions to print the result.
$var = 5;
if ($var == 1) echo 'A';
else if ($var == 2 || $var == 6) echo 'B';
else if ($var == 3 || $var == 5) echo 'C';
else if ($var == 4) echo 'D';
else echo 'X';
//Saída: C
If I do this:
if ($var == 1) echo 'A';
else if ($var == (2 || 6)) echo 'B';
...
Always will print B
.
Questions:
- Why will you always fall into this condition? (
(2 || 6)
= 1 = true? In view, yes, the condition is incorrect) - Is there a way to check multiple possible values without having to repeat the condition 2x or more (
($var == 2 || $var == 6)
)? (typeIN
in SQL language)