Using curly bracket syntax is a bit slower. Consider the following test:
<?php $array = array('key'=>'val'); $start1 = microtime(TRUE); for ($i = 0; $i < 100000; $i++) { $str = "<tag>{$array['key']}</tag>"; } $end1 = microtime(TRUE); $result1 = $end1 - $start1; $start2 = microtime(TRUE); for ($j = 0; $j < 100000; $j++) { $str = "<tag>".$array['key']."</tag>"; } $end2 = microtime(TRUE); $result2 = $end2 - $start2; $start3 = microtime(TRUE); for ($k = 0; $k < 100000; $k++) { $str = '<tag>'.$array['key'].'</tag>'; } $end3 = microtime(TRUE); $result3 = $end3 - $start3; echo "1: $result1\n2: $result2\n3: $result3\n"; ?>
On my PHP / 5.2.19-win32 system, the first test (with curly braces) is a bit slower (~ 7%). However, the difference is so small that you don’t have to worry, and I would say that you like it most.
A little opposite intuitively, the second test is consistently faster than the third (~ 2%) - double quotes are faster than single quotes - and I expected that it would be the other way around.
Daverandom
source share