Print-friendlyPrint-friendly

Double vs Single Quotes in PHP



I picked up this little tid-bit online that helps explain something that has escaped me for awhile about PHP.

In PHP, you can seemingly freely use single quotes (') and double quotes (") around statements of various types. They often are used with echo or print_r commands where you are sending something to the screen.

I have read debates in the past about which one is beter and faster. Because double (") seemed to be easier to work with as far as production goes, I've been using it more lately.

I came across an neat little article on PHP tips at Evolt.org. One such one was regarding the major difference. While speed is a factor, double quotes tells PHP to interpret the code WHILE looking for a variable. If you are echoing a lot of variables and your script is short, double will do ya. Otherwise, single quotes are faster in the long run since they don't have to interpret anything. They serve as sort of a container.

There are so other excellent tips in the article. While many scripts I write are somewhat basic, optimizing them whereever possible can never be a bad thing. Clean coding is seems to be much like good writing. Shorter, simpler many times means better.




Integrated for Your Success ™