arrays - symbol and decimal number true in php -
i have script this
$number = range(0, 9);
when have condition this
if (in_array('@', $number) === true) { echo "true"; }else "false";
and output:
true
and question why symbols same whit number in array $number?? want symbols symbols not number.
example want this
if (in_array('@', $number) === true) { echo "true"; }else "false";
output :
false
from documentation in_array()
:
if third parameter strict set
true
in_array()
function check types of needle in haystack.
in php, casting string doesn't begin number evaluates to 0. 0 exists in array, in_array()
returns true. if don't want happen, set third parameter in_array()
true, performs strong comparison (equivalent ===
) , consider types, too.
if (in_array('@', $number, true) === true) { echo "true"; } else { echo "false"; }
output:
false
Comments
Post a Comment