开发者

Which one is true while making kontrol with php [duplicate]

This question already has answers here: Closed 10 years ago.

Possible Duplicate:

How do the equality (== double equals) and identity (=== triple equals) comparison operators 开发者_高级运维differ?

if (filter_input(INPUT_GET, "email", FILTER_VALIDATE_EMAIL) === 0)

or

if (filter_input(INPUT_GET, "email", FILTER_VALIDATE_EMAIL) == 0)

Should I use == or === here?

Where can I use ===?


=== is used to make a strict comparison, that is, compare if the values are equal and of the same type.

Look at @Ergec's answer for an example.


In your case you should do just:

if (filter_input(INPUT_GET, "email", FILTER_VALIDATE_EMAIL) == false)

or simply

if (filter_input(INPUT_GET, "email", FILTER_VALIDATE_EMAIL))

because filter_input() returns:

Value of the requested variable on success, FALSE if the filter fails, or NULL if the variable_name variable is not set. If the flag FILTER_NULL_ON_FAILURE is used, it returns FALSE if the variable is not set and NULL if the filter fails.


In PHP double equals matches only VALUE

if (2 == "2") this returns TRUE

Triple equals matches VALUE AND TYPE

if (2 === "2") this returns FALSE


You are looking for !== FALSE in that case.

filter_input will either return the filtered variable or FALSE.

=== checks if both sides are equal and of the same type.

!== checks if both sides are not equal and of the same type.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜