提高效率:字符串连接和内插

$arr=array('username'=>'me');


echo  "  value is $arr['username']  ";  这样直接报语法错误 

查了下手册,内插有两种规则,

简单规则 $arr[username]
复杂规则 {$arr['username']}

顺便比较了一下各种写法的效率,时间是运行10000次的累计值

echo 'value is'.$arr['username']; [elapse] => 0.13587594032288
echo "value is {$arr['username']}"; [elapse] => 0.11077213287354
echo  "value is $arr[username] ";  [elapse] => 0.11252403259277

你可能感兴趣的:(字符串,职场,休闲,内插)