符号,并在PHP小数真 [英] symbol and decimal number true in php

查看:119
本文介绍了符号,并在PHP小数真的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的剧本

  $数=范围(0,9);

当我有这样的条件。

 如果(in_array('@',$号)===真){
    回声真;}其他假;

和输出:

 

和我的问题是,为什么这些符号是一样的白衣任意数量的数组$号??
我想只是符号的符号不是数量。

例如,我想这样的

 如果(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 the in_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 for in_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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆