Allowed memory size exhausted in PHP loop
<p>I have the following code: </p>

<pre><code> 15 $users = pg_fetch_all($result);
 16 $chart_data = array();
 17 foreach ($users as $value)
 18 {
 19         //var_dump($value);
 20         $temp = array();
 21         $temp['label'] = $value['id'];
 22         $temp['y'] = $value['sum'];
 23 print_r($temp);
 24 /*
 25 echo "&lt;pre&gt;";
 26         var_dump($temp);
 27 echo "&lt;/pre&gt;";
 28 */      
 29         array_push($chart_data,$temp);
 30 }
 31 echo count($chart_data);
</code></pre>

<p>When I run my code, I get the following error message: </p>

<pre><code>[Thu Apr 28 17:23:39.278844 2016] [:error] [pid 24321] [client 10.63.8.104:58362] PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) in /var/www/localhost/htdocs/audit/index.php on line 21
</code></pre>

<p>This is a sample of the output I get from the print_r(): </p>

<pre><code>Array ( [label] =&gt; 12 [y] =&gt; 0.0021 ) 
</code></pre>

<p>I can't see how line 21 is problematic here. Maybe I need to explicitly reset temp to an empty array??
Not sure too but any suggestions welcome.
Thanks. </p>