Outputting HTML from a PHP function works with Print_r but not with echo
<p>I know that <code>print_r</code> prints arrays and objects and <code>echo</code> does the rest.</p>

<p>My questions is a result of me coding something and somehow the returned variable of a <code>function</code> does not print with <code>echo</code> but it does with <code>print_r</code> or <code>var_dump</code>. I am very pron to believe that this result is a problem with my code rather than a difference between <code>echo</code> and <code>print_r</code> given that the returned variable is a <code>string</code> not an <code>array</code></p>

<p>So my question is as follows: Why the <code>function showPreviousDiscipline</code> only displays the HTML code that it returnt if I put <code>print_r</code> in the template? Shouldn't it display only by me calling the function without the need of <code>echo</code> or <code>print_r</code>? at the end of the day is just text what is outputing</p>

<p>The HTML</p>

<pre><code>&lt;div class="ldcMainWrap"&gt;
&lt;table&gt;
    &lt;tr&gt;
        &lt;td&gt;
            &lt;select multiple="multiple" size="5"&gt; 
            &lt;?php 
// Displays something in the page if is print_r but not if i echo it... or even if i dont put anything...
print_r ($this-&gt;showPreviousDiscipline(1)); 
?&gt;
            &lt;/select&gt;
        &lt;/td&gt;
        &lt;td&gt;
            &lt;select multiple="multiple" size="5"&gt; 
            &lt;/select&gt;
        &lt;/td&gt;
    &lt;tr&gt;
&lt;/table&gt;
&lt;div&gt;
</code></pre>

<p>THE PHP</p>

<pre><code>public function drawWebsite () {
    $tpl = include "step.one.view.php";
    return $tpl;
}

public function showPreviousDiscipline ( $uID ) {   
    $AllUserDetails = parent::$this-&gt;pullUserDetails ( $uID );
    $allDataRaw     = parent::$this-&gt;pullDeparmentTableData ();
    $html       = '';

    // Loops through the array $allDataRaw
    foreach ($allDataRaw as $key =&gt; $val) { 

        foreach ($val  as $key2 =&gt; $val2) {

            //CHECKs if he user has already selected one and if it does it applies a CSS class
            if($key2) {
                if($val2 === $AllUserDetails['rID']) {
                    $html .= '&lt;option value ="'.$val2.'" class="selected"&gt;'.$key2.'&lt;/option&gt;';
                }else {
                    $html .= '&lt;option value ="'.$val2.'" class="unselected"&gt;'.$key2.'&lt;/option&gt;';}
            }
        }   
    }   
    $html           .= ''; 
    return $html;
}
</code></pre>

<p>TEST OUTPUT</p>

<pre><code>        &lt;select multiple="multiple" size="5"&gt; 
  &lt;option value="11" class="unselected"&gt;dID&lt;/option&gt;
    &lt;option value="test1" class="unselected"&gt;dName&lt;/option&gt;
    &lt;option value="" class="unselected"&gt;dDescription&lt;/option&gt;
&lt;option value="22" class="selected"&gt;dID&lt;/option&gt;
    &lt;option value="test2" class="unselected"&gt;dName&lt;/option&gt;
    &lt;option value="" class="unselected"&gt;dDescription&lt;/option&gt; 
               &lt;/select&gt;
</code></pre>
