문제

I tried to use the operators AND, OR in an IF statement in a PHP script like this:

if($user[id]=='1' AND (($_GET['f']=='f-ppas') || ($_GET['f']=='f-kua'))){
   .....
}

But the result is wrong. Can anyone help me?

도움이 되었습니까?

해결책

Change AND to &&

if($user['id']=='1' && (($_GET['f']=='f-ppas') || ($_GET['f']=='f-kua'))){
   .....
}

The AND operator has some precedence problems.

$this = true;
$that = false;

$truthiness = $this and $that;

$truthiness above has the value true. Why? = has a higher precedence than and. The addition of parentheses to show the implicit order makes this clearer:

 ($truthiness = $this) and $that

If you used && instead of and in the first code example, it would work as expected and be false.

Reference: 'AND' vs '&&' as operator

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top