note 98824 added to function.strcmp
| From: | g dot nicolas_89 at hotmail dot fr | Date: | Fri, 09 Jul 2010 15:44:46 +0000 |
| Subject: | note 98824 added to function.strcmp | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-170832@lists.php.net to get a copy of this message | ||
To test if 2 strings are exactly correct, use the operator === instead of strcmp.
Test battery :
//Starting expression :
Expressions :
$a="Testing strcmp";
$b="Testing strcmp";
//Key legend
0 for if(strcmp($a,$b) === 0);
1 for if($a === $b);
For 5000 iterations :
Test #1 : Array ( [0] => 0.145534038544 [1] => 0.109009027481 )
Test #2 : Array ( [0] => 0.145094871521 [1] => 0.108952999115 )
Test #3 : Array ( [0] => 0.145040988922 [1] => 0.109071016312 )
Test #4 : Array ( [0] => 0.144774913788 [1] => 0.108735084534 )
Test #5 : Array ( [0] => 0.145333051682 [1] => 0.10866189003 )
about 7µs faster for each iterations.
Use strcmp to calculate "gap" between string. (e.g. strcmp('a','d') =
-3 (NOT return -1 as I saw in other notes)
----
Server IP: 89.31.146.176
Probable Submitter: 85.116.42.193
----
Manual Page -- http://www.php.net/manual/en/function.strcmp.php
Edit -- https://master.php.net/note/edit/98824
Del: integrated -- https://master.php.net/note/delete/98824/integrated
Del: useless -- https://master.php.net/note/delete/98824/useless
Del: bad code -- https://master.php.net/note/delete/98824/bad+code
Del: spam -- https://master.php.net/note/delete/98824/spam
Del: non-english -- https://master.php.net/note/delete/98824/non-english
Del: in docs -- https://master.php.net/note/delete/98824/in+docs
Del: other reasons-- https://master.php.net/note/delete/98824
Reject -- https://master.php.net/note/reject/98824
Search -- https://master.php.net/manage/user-notes.php