[thelist] single quotes and arrays

Nadeem Hosenbokus nadeem at nadeemh.com
Sun Apr 24 07:45:01 CDT 2016

I gave heredoc a whirl once and couldn't get used to it. Or rather the
advantages of it didn't seem apparent.

Then I ran into problems with spacing and indents on plain text email bodies
and text file outputs and found that heredoc is brilliant for that too.


Nadeem Hosenbokus
(230) 5766 9169

-----Original Message-----
From: thelist-bounces at lists.evolt.org
[mailto:thelist-bounces at lists.evolt.org] On Behalf Of Lee Kowalkowski
Sent: 24 April 2016 15:54
To: thelist at lists.evolt.org
Subject: Re: [thelist] single quotes and arrays

On 24 April 2016 at 12:57, Nadeem Hosenbokus <nadeem at nadeemh.com> wrote:

> If you iterate through your array, you should be able to do this:
>         $output =       '';
>         foreach($row as $id=>$title){
>                 $output .=      "<option value=\"$id\">$title</option>";
>         }
>         echo $output;
> Personally I don't like using escaped double quotes, so the other way 
> is like this:
>         echo('<option
> value="'.$row['id'].'">'.$row['title'].'</option>'."\n");
> Note that the \n has to be in double quotes.

To avoid escaping quotes, new lines, and frequent string concatenation, I
prefer the heredoc syntax to delimit strings of HTML. (if I can't be
bothered to externalise my HTML from my code, of course).



    $optionHtml .= <<< EOT
<option value="$returnValue" $selected>$optionLabel</option> EOT;

Although, I did get tired of using EOT as the identifier, I just use an
underscore. hehe!


* * Please support the community that supports you.  * *

For unsubscribe and other options, including the Tip Harvester and archives
of thelist go to: http://lists.evolt.org Workers of the Web, evolt ! 

More information about the thelist mailing list