Single versus double quotes in PHP
If you want to improve the performance of your PHP pages, always use single quotes for strings as opposed to double quotes. If you use double quotes, the interpreter has to parse the string to make substitutions as needed, and this is slower then just concatenating strings built up using single quotes. For example, use this:
$result = $x . ' + ' . $y . ' = ' . $z;
as opposed to:
$result = "$x + $y = $z";
The only time you really need to use double quotes is when you need to use interpreted characters, such as line feeds. But again, you can break the string into an interpreted section and a non-interpreted section to speed it up, like so:
$result = 'some string with a line feed on the end' . "\n";
$result = $x . ' + ' . $y . ' = ' . $z;
as opposed to:
$result = "$x + $y = $z";
The only time you really need to use double quotes is when you need to use interpreted characters, such as line feeds. But again, you can break the string into an interpreted section and a non-interpreted section to speed it up, like so:
$result = 'some string with a line feed on the end' . "\n";
| Rating: | no ratings, 0 total Votes |
| Categories: | PHP coding programming |
| Added: | on Mar 31, 2007 at 8:00 pm |
| Added By: | Marcos84 |

