note 109292 added to function.is-int
| From: | 2 dot 71828183E0 at gmail dot com | Date: | Tue, 03 Jul 2012 12:46:44 +0000 |
| Subject: | note 109292 added to function.is-int | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-189017@lists.php.net to get a copy of this message | ||
I ran a benchmark for testing "is_int()"-like:
$v=array("q1","q2","1","2",1,2);
$s=microtime(true);
for($i=0;$i<10000000;$i++){
$x=$v[$i%count($v)];
/** compare **/
}
echo "total: ",microtime(true)-$s, "ms", PHP_EOL;
If you'll never have testing zero-values, you can this fastest method:
$x=(int)$x;
isset($v);
total: 6.97873ms
But I depricate it!
Otherwise, you should use this trick:
(int)$x==$x;
total: 7.27195ms
(not $x==(int)$x)
Then, I obtained:
is_int($x);
total: 7.61134ms
is_numeric($x);
total: 7.79037ms
----
Server IP: 195.221.21.36
Probable Submitter: 83.156.236.170
----
Manual Page -- http://www.php.net/manual/en/function.is-int.php
Edit -- https://master.php.net/note/edit/109292
Del: integrated -- https://master.php.net/note/delete/109292/integrated
Del: useless -- https://master.php.net/note/delete/109292/useless
Del: bad code -- https://master.php.net/note/delete/109292/bad+code
Del: spam -- https://master.php.net/note/delete/109292/spam
Del: non-english -- https://master.php.net/note/delete/109292/non-english
Del: in docs -- https://master.php.net/note/delete/109292/in+docs
Del: other reasons-- https://master.php.net/note/delete/109292
Reject -- https://master.php.net/note/reject/109292
Search -- https://master.php.net/manage/user-notes.php