Single quotes, Double quotes

It’s easy to just use double quotes when concatenating strings because it parses everything neatly without having to deal with escaping characters and using dot values. However, using single quotes has considerable performance gains, as it requires less processing.

For Example:

<?php
//Consider this string
$howdy = 'everyone';
$foo = 'hello $howdy';
$bar = "hello $howdy";

// Concatenating this strings
$howdy = 'everyone';
$foo = 'hello $howdy';
$bar = "hello $howdy";
?>

$foo outputs to “hello $howdy” and $bar gives us “hello everyone”. That’s one less step that PHP has to process. It’s a small change that can make significant gains in the performance of the code.

Permanent link to this article: https://blog.openshell.in/2010/11/single-quotes-double-quotes/

Leave a Reply

Your email address will not be published.