php字符串与0整数比较返回true?

标签 php

Possible Duplicate:
Why does PHP consider 0 to be equal to a string?

我有这段代码:

$o['group'] = "prueba";
if( $o['group'] == 0){
    die("test");
}

为什么打印测试?一个字符串怎么可能等于零?

最佳答案

如果您希望它与字符串完全匹配,请尝试使用三个等号的精确类型
if( $o['group'] === 0){
== 将字符串与整数 0 进行比较时始终计算为 true

'a string' == 0 also evaluates to true because any string is converted into an integer when compared with an integer. If PHP can't properly convert the string then it is evaluated as 0. So 0 is equal to 0, which equates as true.

来自 here

关于php字符串与0整数比较返回true?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8671942/

相关文章:

javascript - 更改图像时闪烁

php - 根据条件从数组中获取最小/最大值

php - 如何调用这个php函数

php - 使用fpdf下载pdf后如何重定向

PHP:如何在其自己的类中访问/使用方法?

php - Laravel 框架类在 PHPUnit 数据提供程序中不可用

php - 基于用户输入的MySQL查询

php - 什么可以更好地节省服务器系统资源

php - 通过 urlencode() 输出为 SEO 目标命名非英语字母语言的图像是否合适

php - 在 PHP 中,如何访问对象中的 ":private"数组?