symbol and decimal number true in php(php中的符号和十进制数为真)
问题描述
我有这样的脚本
$number = range(0, 9);
当我有这种情况时
if (in_array('@', $number) === true) {
echo "true";
}else "false";
和输出:
true
我的问题是为什么符号与数组 $number 中的任何数字相同?我想要符号只是符号而不是数字.
and my question is why the symbols is the same whit any number in array $number?? I want symbols just symbols not number.
我想要这样的例子
if (in_array('@', $number) === true) {
echo "true";
}else "false";
输出:
false
推荐答案
来自 in_array() 的文档代码>:
如果第三个参数 strict 设置为 TRUE
那么 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.
在 PHP 中,将任何不以数字开头的字符串转换为 0.0 存在于您的数组中,因此 in_array()
返回 true.如果您不希望发生这种情况,请将 in_array()
的第三个参数设置为 true,以便执行强比较(相当于 ===
)并考虑类型也一样.
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";
}
输出:
false
这篇关于php中的符号和十进制数为真的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:php中的符号和十进制数为真


基础教程推荐
- Libpuzzle 索引数百万张图片? 2022-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- 在多维数组中查找最大值 2021-01-01