note 98824 deleted from function.strcmp by danbrown

From: Date: Fri, 09 Jul 2010 15:47:51 +0000
Subject: note 98824 deleted from function.strcmp by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-170833@lists.php.net to get a copy of this message
Note Submitter: g dot nicolas_89 at hotmail dot fr ---- 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)

« previous php.notes (#170833) next »