note 91404 deleted from function.is-int by googleguy

From: Date: Tue, 22 Oct 2013 12:15:12 +0000
Subject: note 91404 deleted from function.is-int by googleguy
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-197100@lists.php.net to get a copy of this message
Note Submitter: corey at effim dot com ---- 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... <?php $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.

« previous php.notes (#197100) next »