Welcome Guest, Not a member yet? Register   Sign In
When it comes to echoing or setting do you prefer ' or "
#4

[eluser]ejangi[/eluser]
This:
Code:
$string = 'Hello world';
$text = 'My text string: '.$string.', is '.count($string).' characters long';

is much faster than:
Code:
$string = "Hello world";
$count = count($string);
$text = "My text string: {$string}, is {$count} characters long";

for PHP to parse, regardless of how much you have to type.

[EDIT:] The performance gain of single quotes is somewhere between 150% and 200% compared to a double-quoted string containing variables, but in saying that the overall performance hit to your application will be almost unnoticeable, so in truth it's not big enough a issue to go a change all your current applications to use single quotes or anything...

I ALWAYS use single quotes, except on the very rare occasion that I need to add newlines etc... Even then, I'd prefer to have that kind of thing in a view where it belongs. Big Grin


Messages In This Thread
When it comes to echoing or setting do you prefer ' or " - by El Forum - 01-23-2008, 04:32 AM



Theme © iAndrew 2016 - Forum software by © MyBB