php比較兩個字串是否相等,==和strcmp( ) 哪個效率高?
php比較兩個字串是否相等,==和strcmp( ) 哪個效率高?
<code><?php $time1 = microtime(true); $a = $b = 'hello,world!'; $i = $j = 100000000; while($i>0){ $i--; if($a==$b) ; } $time2 = microtime(true); while($j>0){ $j--; if(strcmp($a,$b)); } $time3 = microtime(true); echo ($time2 - $time1)."\n"; echo ($time3 - $time2); //result //$ php demo.php //1.9449820518494 //7.9897949695587 </code>
肯定是== 效率高,因為運算子比函數呼叫省記憶體。