what numeric type is this var

There are some PHP functions that answer the question: Which numeric type of value is stored in this variable? Or, is this numeric? Here they are:

  • is_numeric()
  • is_int()
  • is_float()
  • is_finite()
  • is_infinite()
  • is_nan() — is not a number

I wouldn’t use these functions before reading the PHP manual if I were you.

I’ve heard that is_int() does not accurately reflect the definition of an int because it allows for negative values and zero or something. Someone came up with this intead:

function really_is_int($val)
  if(func_num_args() !== 1)
      exit(__FUNCTION__.'(): not passed 1 arg');

  return ($val !== true) && ((string)abs((int) $val)) === ((string) ltrim($val, '-0'));

About samehramzylabib

See About on https://samehramzylabib.wordpress.com
This entry was posted in Coding, PHP Math. Bookmark the permalink.


Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s