Depending on the version of PHP, it depends on how much the second is faster if you write it like this: $newstring = $a . ' and ' . $b . ' went out to see ' . $c; $newstring = $a . ' and ' . $b . ' went out to see ' . $c;
PHP is very incompatible from version to version and builds to build, when it comes to performance, you should check it out for yourself. What needs to be said is that it also depends on the types of $a , $b and $c , as you can see below.
When you use " , PHP parses the string to see if it has any variable / placeholders, but if you only use ' , PHP treats it as a simple string without further processing. Therefore, usually ' should be faster. At least , in theory. In practice, the test should .
Results (in seconds):
a, b, c are integers: all inside " : 1.2370789051056 split up using " : 1.2362520694733 split up using ' : 1.2344131469727 a, b, c are strings: all inside " : 0.67671513557434 split up using " : 0.7719099521637 split up using ' : 0.78600907325745 <--- this is always the slowest in the group. PHP, 'nough said
Using this code with Zend Server CE PHP 5.3:
<?php echo 'a, b, c are integers:<br />'; $a = $b = $c = 123; $t = xdebug_time_index(); for($i = 1000000; $i > 0; $i--) $newstring = "$a and $b went out to see $c"; $t = xdebug_time_index() - $t; echo 'all inside " : ', $t, '<br />'; $t = xdebug_time_index(); for($i = 1000000; $i > 0; $i--) $newstring = $a . " and " . $b . " went out to see " . $c; $t = xdebug_time_index() - $t; echo 'split up using " : ', $t, '<br />'; $t = xdebug_time_index(); for($i = 1000000; $i > 0; $i--) $newstring = $a . ' and ' . $b . ' went out to see ' . $c; $t = xdebug_time_index() - $t; echo 'split up using \' : ', $t, '<br /><br />a, b, c are strings:<br />'; $a = $b = $c = '123'; $t = xdebug_time_index(); for($i = 1000000; $i > 0; $i--) $newstring = "$a and $b went out to see $c"; $t = xdebug_time_index() - $t; echo 'all inside " : ', $t, '<br />'; $t = xdebug_time_index(); for($i = 1000000; $i > 0; $i--) $newstring = $a . " and " . $b . " went out to see " . $c; $t = xdebug_time_index() - $t; echo 'split up using " : ', $t, '<br />'; $t = xdebug_time_index(); for($i = 1000000; $i > 0; $i--) $newstring = $a . ' and ' . $b . ' went out to see ' . $c; $t = xdebug_time_index() - $t; echo 'split up using \' : ', $t, '<br />'; ?>