RE: [PHP] is_numeric for php3
| From: | Steve Edberg | Date: | Wed, 29 Aug 2001 00:10:41 +0000 |
| Subject: | RE: [PHP] is_numeric for php3 | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-64924@lists.php.net to get a copy of this message | ||
At 03:41 PM 8/28/01 , scott [gts] wrote:
my understanding is that numeric is a broad term for number values (any value with only numbers and a decimal point) like 1, 5.6, 332, 0.5532, for example. integers are a sub-set of numerics, so any integer is a numeric value, but any numeric value is not necessarily an integer. $num=123 is an integer *and* numeric value. $num='123' might not be an integer, but it is a numeric. now the problem of how to devise a proper test for numeric values (without using regexps) is what i'd like to see.function is_numeric($Something) { return (string)(1.0*$Something) == $Something; } should work.
-steve+------------------------------------------------------------------------+
| Steve Edberg University of California, Davis | | sbedberg@ucdavis.edu (530)754-9127 | | http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ |+---------------------- Gort, Klaatu barada nikto! ----------------------+