OR statement returning wrong number

前端 未结 4 613
悲&欢浪女
悲&欢浪女 2021-01-29 15:41

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;
f=0;

if(e==1){f=1;}
if(e==2){f=2         


        
4条回答
  •  感情败类
    2021-01-29 16:27

    Try replacing :

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

    with

    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

提交回复
热议问题