randomcompat_intval


randomcompat_intval ( $number, $fail_open = false )

Parameters:
  • (int|float) $number The number we want to convert to an int
  • (bool) $fail_open Set to true to not throw an exception
Returns:
  • (float|int)
Defined at:

Description

Cast to an integer if we can, safely.

If you pass it a float in the range (~PHP_INT_MAX, PHP_INT_MAX) (non-inclusive), it will sanely cast it to an int. If you it's equal to ~PHP_INT_MAX or PHP_INT_MAX, we let it fail as not an integer. Floats lose precision, so the <= and => operators might accidentally let a float through.

Related Functions

randomcompat_strlen, randomcompat_substr, random_int, random_bytes, allow_subdomain_install

Top Google Results

User discussions

wpseek mobile