note 98821 added to function.count
| From: | g dot nicolas_89 at hotmail dot fr | Date: | Fri, 09 Jul 2010 15:00:46 +0000 |
| Subject: | note 98821 added to function.count | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-170825@lists.php.net to get a copy of this message | ||
To test if an array is empty, prefer use empty than count==0.
Look this stats :
Expression : $a= array();
//Key legend
0 for if(empty($a))
1 for if(count($a) == 0)
2 for if(count($a) === 0)
3 for if(!count($a))
For 1000 iterations :
Test #1 : Array ( [0] => 0.0190088748932 [1] => 0.0262041091919 [2] => 0.0264089107513 [3]
=> 0.0246360301971 )
Test #2 : Array ( [0] => 0.0191049575806 [1] => 0.0265319347382 [2] => 0.0264468193054 [3]
=> 0.0246489048004 )
Test #3 : Array ( [0] => 0.01922082901 [1] => 0.0262050628662 [2] => 0.0264029502869 [3]
=> 0.024729013443 )
Test #4 : Array ( [0] => 0.0191278457642 [1] => 0.0262858867645 [2] => 0.0264329910278 [3]
=> 0.0247249603271 )
Test #5 : Array ( [0] => 0.0190749168396 [1] => 0.0263991355896 [2] => 0.0263121128082 [3]
=> 0.0247128009796 )
Test #6 : Array ( [0] => 0.0191838741302 [1] => 0.0262401103973 [2] => 0.0264360904694 [3]
=> 0.0245780944824 )
Test #7 : Array ( [0] => 0.0192511081696 [1] => 0.0262877941132 [2] => 0.026477098465 [3]
=> 0.0244669914246 )
Test #8 : Array ( [0] => 0.0190861225128 [1] => 0.0263922214508 [2] => 0.0263969898224 [3]
=> 0.0246238708496 )
Test #9 : Array ( [0] => 0.0191929340363 [1] => 0.0262160301208 [2] => 0.026976108551 [3]
=> 0.0244481563568 )
Test #10 : Array ( [0] => 0.019070148468 [1] => 0.0260848999023 [2] => 0.0262608528137 [3]
=> 0.0245189666748 )
Average :
empty use 0.0191xxx for 1000 iterations
count use 0.026xxxx (in best case 0.024xxxx) for 1000 iterations
----
Server IP: 195.221.21.36
Probable Submitter: 85.116.42.193
----
Manual Page -- http://www.php.net/manual/en/function.count.php
Edit -- https://master.php.net/note/edit/98821
Del: integrated -- https://master.php.net/note/delete/98821/integrated
Del: useless -- https://master.php.net/note/delete/98821/useless
Del: bad code -- https://master.php.net/note/delete/98821/bad+code
Del: spam -- https://master.php.net/note/delete/98821/spam
Del: non-english -- https://master.php.net/note/delete/98821/non-english
Del: in docs -- https://master.php.net/note/delete/98821/in+docs
Del: other reasons-- https://master.php.net/note/delete/98821
Reject -- https://master.php.net/note/reject/98821
Search -- https://master.php.net/manage/user-notes.php