我阅读PHP手册和我碰到type juggling如何看待字符串作为一个字符串,而不是在PHP
我很困惑,因为我从来没有碰到过这样的事情来了。
$foo = 5 + "10 Little Piggies"; // $foo is integer (15)
当我用这个代码,它返回我15,它增加了10 + 5,当我使用is_int()
它返回我真即。 1
,我在等一个错误,它以后引用我String conversion to numbers
在那里我阅读If the string starts with valid numeric data, this will be the value used. Otherwise, the value will be 0 (zero)
$foo = 1 + "bob3"; /* $foo is int though this doesn't add up 3+1
but as stated this adds 1+0 */
现在我应该怎么做,如果我想治疗10只小小猪或bob3为string
,而不是作为一个int
。使用settype()
也不起作用。我想要一个错误,我不能将5添加到字符串中。
-1问题严重吗? com'on懦夫来吧,并回答我,为什么连续无故地降低我的问题和答案? –