is_int
checks the actual type of a variable, which is string
in your case. Use is_numeric
for numeric values regardless of variable type.
Note that the following values are all considered "numeric":
"1"
1
1.5
"1.5"
"0xf"
"1e4"
i.e. any floats, integers or strings that would be valid representations of floats or integers.
Edit: Also, you might have misunderstood array_filter
, it does not return true or false but a new array with all values for which the callback function returned true. if($only_integers)
works nonetheless (after you fixed your assignment operator) because all non-empty arrays are considered "true-ish".
Edit 2: as @SDC pointed out, you should use ctype_digit
if you only want to allow integers in decimal format.