note 37205 added to function.is-int
| From: | phpContrib at rn2 dot php dot net | Date: | Thu, 06 Nov 2003 17:42:10 +0000 |
| Subject: | note 37205 added to function.is-int | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-60010@lists.php.net to get a copy of this message | ||
// Just to be pedantic... ;)
// extreme-ints (!) like this will not work with previous function:
Test ("10.01e2" );
// 10.01e2 is 1001
// This one:
function myIsInt($x) {
return ( is_numeric ($x ) ? intval(0+$x ) == $x : false );
}
// will work even on these paranoid cases...
Note that:
0+$x => converts object to float
intval converts float to int
== converts string to float
so this is exactly like
return (is_numeric ($x ) ? (float)((int)((float)$x)) === (float)$x : false) ;
or with one conversion to float less...
function real_is_intValued($var) {
if(is_numeric($var)) {
$var=(float)$var;
return ((float)(int)$var)===$var;
}
return FALSE;
}
----
Manual Page -- http://www.php.net/manual/en/function.is-int.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+37205
Delete -- http://master.php.net/manage/user-notes.php?action=delete+37205&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+37205&report=yes
Search -- http://master.php.net/manage/user-notes.php