title: foreach loop inside variable
body: <p>Here is a situation I need to display values from array through foreach loop inside variable and than echo that variable inside  HTML table. Thanks in Advance. . I have checked all related links in stackoverflow  some links are given  below. </p>
  
  <p><a href="https://stackoverflow.com/questions/10258345/php-simple-foreach-loop-with-html">PHP  simple foreach loop with HTML [closed]</a></p>
  
  <p>My  question is about store looping array inside a variable.. And their is no similarity in another and my question</p>
  
  <p>I want my output to be this way below
  <a href="https://i.stack.imgur.com/M4dnr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/M4dnr.png" alt="Output link"></a></p>
  
  <p>I'm getting this error image given below
  <a href="https://i.stack.imgur.com/Zvu7F.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Zvu7F.png" alt="Error image link here"></a></p>
  
  <p>php filename: foreachloop.php</p>
  
  <pre><code>    &lt;?php
  $arr = array("Apple","orange","strawberry");
  $abc = '&lt;table border="2"&gt;
              &lt;tr&gt;
                  &lt;th&gt;Names&lt;/th&gt;
              &lt;/tr&gt;
              foreach($arr as $key){
              &lt;tr&gt;
                  &lt;td&gt;'.$key.'&lt;/td&gt;
              &lt;/tr&gt;
          }
          &lt;/table&gt;';
  
  echo $abc;
  ?&gt;
  </code></pre>