This isn't an answer per se, but this is too much to put in a comment:
function isFloatOrInt($var)
{
$type = gettype($var);
switch ($type) {
case 'integer':
case 'double':
return true;
case 'string':
//check for number embedded in strings "1" "0.12"
return preg_match('/^[0-9]+(?:\.[0-9]+)?$/', $var);
default:
return false;
}
Preg match can be useful here if you consider the string version of a number to still be a number.
You say
But not string
But does that mean this 'string' or this '10' instead of 10 for example, ie. a string that is also a number?
There is probably many ways to do this, but there are some edge cases so it's largely depends on your needs. For example is an octet a number to you 0777 or and exponent 12e4 or even Hexadecimal 0xf4c3b00c?
$number = is_int($value) || is_float($value)gettype( $var )returnsdoublefor floats, if I recall correctly.is_numeric($value) && !is_string($value)is an alternative to the first comment.