PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
which can be sometimes misused because sometimes people use it on numbers that start with 0.. which isn't an integer.
In that case, you should use is_numeric()
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
but PHP isn't type strict? "6" is the same as 6? that's what I've come to understand.
but anyways, help me learn here
how do you know the OP is looking for a string?
couldn't $value be an int or a string?
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Can only agree with feyd. Relying on a regex to check for a number as string is OTT, unless you require a specific format. Otherwise use the far more scaleable is_numeric(). This will validate any variable type as numeric (though not necessarily an integer!)
ctype_digit() generally accepts only known strings - so be careful you don't use it where the parameter could be a valid integer, or use ctype_digit( (string) $somevar ); to make certain.
If that confused you - use is_numeric(), then cast to integer if that's the number type you expect.