3 ms·
I have this function in my own code. You can adjust it's permissiveness your taste: function is_intval($value) { if (is_integer($value)) return true;
by wvenable 16y ago
I have this function in my own code. You can adjust it's permissiveness your taste:
function is_intval($value)
{
if (is_integer($value)) return true;
if (is_bool($value)) return true;
if (!is_numeric($value)) return false;
if (is_float($value) && floatval(intval($value)) == $value) return true;
if (is_string($value) && strval(intval($value)) == $value) return true;
return false;
}
- pilif 16y ago... hereby proving my point that PHP's default conversions are a bit... strange.
- wvenable 16y agoI never said it wasn't weird!! I just said that it's not really a practical problem in most cases. Perhaps you do have to be extra careful and I'm just so used to it that I don't give it a second thought.