[英]php inarray returns TRUE for the value ZERO
I am trying to use in_array function and its returning TRUE if the value is ZERO. 我正在尝试使用in_array函数 ,如果值为零 ,则返回TRUE。 var_dump also returning bool TRUE var_dump也返回布尔值TRUE
$srcElement=0;
var_dump(in_array($srcElement,array('HA','DA','SA','CA')));
if (in_array($srcElement,array('HA','DA','SA','CA')))
{
echo "VALUE EXISTS";
}
else
{
echo "VALUE NOT FOUND";
}
and getting output as 并输出为
bool(true) VALUE EXISTS
in case of ZERO if I use any other integers its returning ELSE PART. 在零的情况下,如果我使用其他整数,则返回的其他部分。 is there any specific reason behind this ? 这背后有什么具体原因吗?
There is type conversions, while doing the comparisons. 在进行比较时,有类型转换。 Try with strict comparisons. 尝试进行严格的比较。
in_array($srcElement,array('HA','DA','SA','CA'),true);
var_dump(in_array($srcElement,array('HA','DA','SA','CA')));
will print false
. 将打印false
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.