符号,并在PHP小数真 [英] symbol and decimal number true in php
问题描述
我有这样的剧本
$数=范围(0,9);
当我有这样的条件。
如果(in_array('@',$号)===真){
回声真;}其他假;
和输出:
真
和我的问题是,为什么这些符号是一样的白衣任意数量的数组$号??
我想只是符号的符号不是数量。
例如,我想这样的
如果(in_array('@',$号)===真){
回声真;}其他假;
输出:
假
如果严格的第三个参数设置为
TRUE
那么in_array()
函数也将检查的类型在大海捞针。
块引用>在PHP,铸造,不以数字开头的字符串的计算结果为0。0存在于您的阵列中,使
in_array()
返回true。如果你不希望这种情况发生,设置in_array第三个参数()
来真的,所以它执行强大的比较(相当于= ==
),并考虑类型了。如果(in_array('@',$号,真)===真){
回声真;
}
其他{
回声假;
}输出:
假
I have script like this
$number = range(0, 9);
when I have condition like this
if (in_array('@', $number) === true) { echo "true"; }else "false";
and output:
true
and my question is why the symbols is the same whit any number in array $number?? I want symbols just symbols not number.
example I want like this
if (in_array('@', $number) === true) { echo "true"; }else "false";
output :
false
解决方案From the documentation for
in_array()
:If the third parameter strict is set to
TRUE
then thein_array()
function will also check the types of the needle in the haystack.In PHP, casting any string that doesn't begin with a number evaluates to to 0. The 0 exists in your array, so
in_array()
returns true. If you don't want this to happen, set the third parameter forin_array()
to true, so it performs a strong comparison (equivalent to===
) and consider the types, too.if (in_array('@', $number, true) === true) { echo "true"; } else { echo "false"; }
Output:
false
这篇关于符号,并在PHP小数真的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!