note 37205 deleted from function.is-int by colder

From: Date: Fri, 23 Mar 2007 08:43:26 +0000
Subject: note 37205 deleted from function.is-int by colder
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-124739@lists.php.net to get a copy of this message
Note Submitter: phpContrib (A T) esurfers d o t c o m ---- // 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; }

« previous php.notes (#124739) next »