title: How to implement foreach loop in echo in php
body: <p>This is my code:</p>
  
  <pre><code>&lt;div class="col-xs-6"&gt;
    &lt;div class="form-group"&gt;
      &lt;label&gt;&lt;i class="fa fa-asterisk text-danger"&gt;&lt;/i&gt; Country&lt;/label&gt;
      &lt;select class="form-control select2" id="countryId" name="countryId"&gt;
      &lt;option value="0"&gt;Select Country&lt;/option&gt;
        &lt;?php
          if(!empty($country))
          {
            foreach ($country as $record)
            {
                ?&gt;
                &lt;option value="&lt;?php echo $record-&gt;id ?&gt;"&gt;&lt;?php echo $record-&gt;countryName ?&gt;&lt;/option&gt;
                &lt;?php
            }
          }
        ?&gt;
      &lt;/select&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>This is my trying (Not successful):</p>
  
  <pre><code>echo '
  &lt;div class="col-xs-6"&gt;
    &lt;div class="form-group"&gt;
      &lt;label&gt;'.(($required&lt;&gt;'0')?'&lt;i class="fa fa-asterisk text-danger"&gt;&lt;/i&gt;':"").' '.$friendlyName.'&lt;/label&gt;
      &lt;select '.(($readonly&lt;&gt;'0')?'readonly':"").' '.(($disabled&lt;&gt;'0')?'disabled':"").' class="form-control select2 '.$columnClass.'" id="'.$columnId.'" name="'.$columnName.'"&gt;
        &lt;option value="0"&gt;Select Country&lt;/option&gt;'.
          if(!empty($country))
          {
            foreach ($country as $record)
            {
                .'&lt;option value="$record-&gt;id"&gt;$record-&gt;countryName&lt;/option&gt;'.
            }
          }
      .'&lt;/select&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  ';
  </code></pre>
  
  <p>When i run echo code it gives me this error: <code>Parse error: syntax error, unexpected 'if' (T_IF)</code></p>
  
  <p>How do I echo this block of html and php including foreach loop.</p>