note 81197 added to function.ctype-digit
| From: | Daijoubu at osu1 dot php dot net | Date: | Mon, 18 Feb 2008 08:44:56 +0000 |
| Subject: | note 81197 added to function.ctype-digit | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-136238@lists.php.net to get a copy of this message | ||
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
----
Server IP: 216.235.15.211
Probable Submitter: 69.156.8.89
----
Manual Page -- http://www.php.net/manual/en/function.ctype-digit.php
Edit -- https://master.php.net/note/edit/81197
Del: integrated -- https://master.php.net/note/delete/81197/integrated
Del: useless -- https://master.php.net/note/delete/81197/useless
Del: bad code -- https://master.php.net/note/delete/81197/bad+code
Del: spam -- https://master.php.net/note/delete/81197/spam
Del: non-english -- https://master.php.net/note/delete/81197/non-english
Del: in docs -- https://master.php.net/note/delete/81197/in+docs
Del: other reasons-- https://master.php.net/note/delete/81197
Reject -- https://master.php.net/note/reject/81197
Search -- https://master.php.net/manage/user-notes.php