PHP中数字和字符串值的区别 [英] Difference between numeric and string value in PHP
本文介绍了PHP中数字和字符串值的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在比较 PHP 中的 0
和 '0'
两个字符串时,我发现了差异.我可以做些什么来使它们在 if 操作中被同等比较吗?
I am getting a difference when comparing two string which are 0
and '0'
in PHP. Can I do anything to make them be compared equally in an if action?
谢谢!
推荐答案
如果比较使用:
if ('0' == 0) // if '0' is equal to 0
当将值与转换为数字的字符串进行比较时,它应该返回 true.如果你这样做:
it should return true as the values are compared with the string being converted to a number. If you do:
if ('0' === 0) // if '0' is identical to 0
它会返回 false,因为它们也必须是相同的类型.
it will return false as they have to be of the same type too.
注意三重="
这篇关于PHP中数字和字符串值的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文