php true true true,php-为什么此评估为true

标签:php

乳清这算是真的吗?

$val2=0;

//outputs that is an error123

if($val2=='error123'){

echo 'that is an error123
';

}else{

echo 'that is not an error123
';

}

解决方法:

您正在将字符串与整数进行比较.为了进行比较,首先将字符串转换为整数.当“ error123”转换为整数时,它变为0.

echo intval("error123");

结果:

0

If you compare a number with a string or the comparison involves numerical strings, then each string is converted to a number and the comparison performed numerically.

有一个快速参考页PHP type comparison tables,向您显示各种比较的结果.请参阅表格“与==的宽松比较”.关于这个问题,有趣的部分是0 ==“ php”显示为TRUE.

如果您不希望类型变戏法,请使用===而不是==.

标签:php

来源: https://codeday.me/bug/20191012/1900902.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值