note 91404 added to function.is-int
| From: | corey at effim dot com | Date: | Tue, 09 Jun 2009 20:21:50 +0000 |
| Subject: | note 91404 added to function.is-int | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-156650@lists.php.net to get a copy of this message | ||
If you're concerned with speed, you can save yourself about 50% of the time it takes to check
whether or not something is an integer pretty easily...
Running through 10,000 iterations of each of the following 3 methods outputs fairly consistently...
<?
$foo = is_int($i);
// 0.0032429695129395 seconds
$foo = ((int) $i) == $i;
// 0.0020270347595215 seconds
$foo = ((int) $i) === $i;
// 0.001600980758667 seconds
?>
So if you want the best performance and know you're not going to be passed a string that needs
to be typed as an integer, use === to compare the type as well.
----
Server IP: 64.71.164.2
Probable Submitter: 72.177.49.202
----
Manual Page -- http://www.php.net/manual/en/function.is-int.php
Edit -- https://master.php.net/note/edit/91404
Del: integrated -- https://master.php.net/note/delete/91404/integrated
Del: useless -- https://master.php.net/note/delete/91404/useless
Del: bad code -- https://master.php.net/note/delete/91404/bad+code
Del: spam -- https://master.php.net/note/delete/91404/spam
Del: non-english -- https://master.php.net/note/delete/91404/non-english
Del: in docs -- https://master.php.net/note/delete/91404/in+docs
Del: other reasons-- https://master.php.net/note/delete/91404
Reject -- https://master.php.net/note/reject/91404
Search -- https://master.php.net/manage/user-notes.php