Does php's is_int function return false
for negative numbers because integers in php are unsigned, or is there other behaviour that I'm missing? I'm trying to check if something is a whole number, and I don't want to rely on that behaviour of is_int (for the first part of the test) if it's doing something different.
Clarification: I know that is_int
returns false
for negative numbers, but I'm asking why because of this behaviour: var_dump(intval("-10"))
prints int(-10)
, and var_dump(intval("10"))
prints int(1)
, so both negative and positive values are considered integers, yet is_int("-10")
returns false.
EDIT: Ok, sorry everyone, I got quite a bit confused about the behaviour of is_int and integers in general. I was thinking of it acting on a string with contents like "-10" when what I need is is_numeric
on a string, or is_int
on an integer itself. Thanks for the help.
It doesn't:
var_dump( is_int(-10) ); // bool(true)
Probably, it isn't a number to begin with:
var_dump( is_int('-10') ); // bool(false)
If so, try out is_numeric(), which is designed for strings.
Why not test it for yourself?
<?php
var_dump(is_int(-1));
var_dump(is_int('-1'));
produces:
bool(true)
bool(false)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With