title: How Do i use array_push in foreach loop PHP?
body: <p>Here is example which I have try</p>
  
  <pre><code>&lt;?php
   include 'spider/classes/simple_html_dom.php';
   $html = new simple_html_dom();
   $html-&gt;load("&lt;html&gt;&lt;body&gt;&lt;h2&gt;Heading 1&lt;/h2&gt;&lt;h2&gt;This heading 2&lt;/h2&gt;&lt;/p&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;");
   $e = $html-&gt;find("h2", 0);
   $key = array();
   if($e-&gt;plaintext != ""){
   foreach($html-&gt;find("h2", 0) as $e){
      //echo $e-&gt;plaintext;
      array_push($key, $e-&gt;plaintext);
    }
   } else {
       echo "error";
   }
   print_r($key);
   ?&gt;
  </code></pre>
  
  <p><strong>Result:</strong><br />
  Array ( [0] => [1] => [2] => [3] => [4] => [5] => Heading 1This heading 2</p>
  
  <p>[6] => [7] => ) </p>
  
  <p>How Do i use array_push to create an array?</p>