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中的符号和十进制数为真


基础教程推荐
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 如何替换eregi() 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01