Bite of Php

Bite of PHP: Switch Statement

Published: August 13, 2015

The "switch" statement within various languages, contains a similar structure. This makes the PHP switch statement familiar. A failing example of PHP's switch statement was brought up yesterday at work. Someone asked why the expected responses to this were not received. php <?php $convertQ = function ($str) { switch ($str) { case 0: return 'no'; case 'No': return 'no'; case…

Read more...

Bite of PHP: Heredoc vs. Nowdoc

Published: April 23, 2015

Heredoc Heredoc will define a string of text in a what-you-see-is-what-you-mean type of format. So, if you want to echo out structured text, like so: text I think that I Shall never pay As much as I Have for 2015-04-23 You would put it in a heredoc like this: php $today = date('Y-m-d'); $poem = <<<HTML I think that I…

Read more...

Bite of PHP: Double vs Single Quote Echo

Published: March 04, 2015

In PHP, we have two ways of formatting an echo statement: we can choose to use single-quotes or double-quotes. The choice is less dependent upon which side of the Atlantic we learned to read and more dependent upon what we hope to accomplish with echoing that string. If you want to echo the string without parsing it, use single-quotes. If…

Read more...