[thelist] single quotes and arrays

Lee Kowalkowski lee.kowalkowski at googlemail.com
Sun Apr 24 06:53:54 CDT 2016

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>

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


More information about the thelist mailing list