Chanヨネ Chanヨネ - 8 months ago 33
PHP Question

OR statement returning wrong number

If i put 1 or 2 into this it will return 4. Why is this?I'm more used to python stuff so sorry if this is rather basic.

e = 1;

if(e== 3 or 4){f=4;}
echo f;


Try replacing :

if(e== 3 or 4){f=4;}


if(e == 3 or e == 4){ f=4; }

The value 4 is considered to be TRUE by the language. In your code, 1 == 3 is FALSE, so the if statement is looking at (FALSE or TRUE) which is equals TRUE, so f is set to 4.

Have a look at this link re: PHP Booleans