それをねじ込み、私はベンチマークを行いました:
<?php
$shortstring='hello';
$longstring='long';
for($run=0;$run<100000;$run++)
$longstring.='dsffghdgfhdsda'.rand(1000,2000);
$time=microtime(true);
for($run=0;$run<100000000;$run++)
$temp=strlen($shortstring);
$time=microtime(true)-$time;
echo "strlen on short string took $time seconds\n";
$time=microtime(true);
for($run=0;$run<100000000;$run++)
$temp2=strlen($longstring);
$time=microtime(true)-$time;
echo "strlen on long string took $time seconds\n";
結果
strlen on short string took 12.508891820908 seconds
strlen on long string took 11.897696971893 seconds
明らかに文字列を反復処理しませんが、事前にインデックス付けされた値を返します。速度に違いはありません。