note 81197 deleted from function.ctype-digit by betz
| From: | betz@php.net | Date: | Mon, 18 Feb 2008 10:01:46 +0000 |
| Subject: | note 81197 deleted from function.ctype-digit by betz | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-136241@lists.php.net to get a copy of this message | ||
Note Submitter: Daijoubu
Reason: useless
----
You can also make use of PHP loose type comparaison:
<?php
$vars = array("10", 10, '10.9', 10.9, 'ten');
foreach ($vars as $var)
{
if ((string)intval($var) == $var)
{
echo 'true';
}
else
{
echo 'false';
}
}
?>
Returns true, true, false, false, false
The casting to (string) is necessery as PHP automaticly converts
string to number when you compare an interger to a string
See the manual:
language.types.string.php#language.types.string.conversion