PHP echo quotes

Whenever I write PHP code, I always use single quotes to echo text, escaping apostrophes and necessary single quote marks with backslashes. Since “double quotes” are much more common in English than ‘single quotes,’ this requires less escaping, and the PHP parser parses single quotes slightly faster because it does not check the string for variables. For example,<?php $test = 100; echo ‘$test’; ?> will return “$test” whereas <?php $test = 100; echo “$test”; ?> will return “100”. Expanding on this, to include variables in single quote echo s, print s, printf s, die s, etc., they must be concatenated like so: <?php echo ‘Today is ‘ . $date . ‘ and the weather is ‘ . $current_weather . ‘!’; ?>. As you can see, I included spaces around the single quotes around the concatenation because those are the English spaces on the left and right sides. This is not necessarily the best way to write statements, but it’s the way I prefer and it’s best to stick with one style of programming (house style) and use it consistently. The same statement could be written as <?php echo “Today is $date and the weather is $current_weather!”; ?>, but that could get confusing later due to the way the human mind works.

Sometimes, it may be necessary to construct conditions based on idiosyncrasies in the English language, i.e. plural forms like <?php if($dog_count == 1) $word = ‘dog’; else $word = ‘dogs’; ?> or suffixes like <?php if(substr($num, -1) == ‘1’) $suffix = ‘st’; elseif(substr($num, -1) == ‘2’) $suffix = ‘nd’; elseif(substr($num, -1) == ‘3’) $suffix = ‘rd’; else $suffix = ‘th’; ?>. These are best handled with reusable functions.