Question

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.

I then call a function: 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. At the beginning of the called function, it checks to see if $key is_int. It is returning false when I am calling it with an integer value.

Was it helpful?

Solution

Since everything you fetch from the database is a type string, you could try using is_numeric() instead of is_int().

OTHER TIPS

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:

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

Perhaps try the ctype_digit() function.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top