note 82857 added to function.is-int
| From: | SimonNeaves at osu1 dot php dot net | Date: | Tue, 29 Apr 2008 18:14:08 +0000 |
| Subject: | note 82857 added to function.is-int | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-138906@lists.php.net to get a copy of this message | ||
I've found that both that is_int and ctype_digit don't behave quite as I'd expect, so
I made a simple function called isInteger which does. I hope somebody finds it useful.
<?php
function isInteger($input){
return(ctype_digit(strval($input)));
}
var_dump(is_int(23)); //bool(true)
var_dump(is_int("23")); //bool(false)
var_dump(is_int(23.5)); //bool(false)
var_dump(is_int(NULL)); //bool(false)
var_dump(is_int("")); //bool(false)
var_dump(ctype_digit(23)); //bool(true)
var_dump(ctype_digit("23")); //bool(false)
var_dump(ctype_digit(23.5)); //bool(false)
var_dump(ctype_digit(NULL)); //bool(false)
var_dump(ctype_digit("")); //bool(true)
var_dump(isInteger(23)); //bool(true)
var_dump(isInteger("23")); //bool(true)
var_dump(isInteger(23.5)); //bool(false)
var_dump(isInteger(NULL)); //bool(false)
var_dump(isInteger("")); //bool(false)
?>
----
Server IP: 92.48.100.16
Probable Submitter: 82.71.8.209
----
Manual Page -- http://www.php.net/manual/en/function.is-int.php
Edit -- https://master.php.net/note/edit/82857
Del: integrated -- https://master.php.net/note/delete/82857/integrated
Del: useless -- https://master.php.net/note/delete/82857/useless
Del: bad code -- https://master.php.net/note/delete/82857/bad+code
Del: spam -- https://master.php.net/note/delete/82857/spam
Del: non-english -- https://master.php.net/note/delete/82857/non-english
Del: in docs -- https://master.php.net/note/delete/82857/in+docs
Del: other reasons-- https://master.php.net/note/delete/82857
Reject -- https://master.php.net/note/reject/82857
Search -- https://master.php.net/manage/user-notes.php