I searched on StackOverflow and Google and I can\'t find the answer to this question:
Should we always use the triple equal in PHP for validation?
For exampl
if (is_numeric($x) && $x == '1') { ...
This looks redundant to me. Why do we need to check if $x
is_numeric
AND the value '1'
? We know '1'
is numeric so if it is equal to '1'
then it must be a number.
You could use ===
comparison:
If you're fine with interpreting it as a string:
if ($x === '1') { ...
or
If you must interpret the value as an int
if ((int) $x === 1) { ...
or
If you don't care about the actual type:
if ($x == '1') { ...