简体   繁体   English

PHP整数类型在函数调用中丢失

[英]PHP integer type getting lost on function call

I have some code that pulls database primary keys and iterates through them by calling a function. 我有一些代码可以提取数据库主键,并通过调用函数来遍历它们。

When I get the key from the database and do a is_int($key) it returns true. 当我从数据库中获取密钥并执行is_int($ key)时,它将返回true。

I then call a function: thisfunction($key) 然后我调用一个函数:thisfunction($ key)

In the calling function, I made it so that you could pass in the $key and that function loads the row for that key or you can pass the row as an object. 在调用函数中,我做到了这一点,以便您可以传入$ key,并且该函数将加载该键的行,也可以将该行作为对象传递。 At the beginning of the called function, it checks to see if $key is_int. 在被调用函数的开头,它将检查$ key是否为is_int。 It is returning false when I am calling it with an integer value. 当我使用整数值调用它时,它将返回false。

Everything you get from database is string. 您从数据库获得的所有内容都是字符串。

That means, even if you have database with INTs for columns, you are going to get them like: 这意味着,即使您的列具有INT的数据库,您也将像这样获得它们:

id, name, age
array("43", "Rok", "19");

也许尝试ctype_digit()函数。

由于您从数据库中获取的所有内容都是类型字符串,因此您可以尝试使用is_numeric()而不是is_int()。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM