xarlotie Posted August 4, 2009 Share Posted August 4, 2009 please help me optimize/arrange this code so that the array wont use too much memory to avoid fatal errors..thanks! while($row = mysql_fetch_array($q3)) { for($i=1;$i<=21;$i++) { $hi = number_format($storePrices[$i] + 0.0003,4); $lo = number_format($storePrices[$i] - 0.0003,4); $openPrc = number_format($row['open_price'],4); if(($hi > $openPrc && $openPrc > $lo) || $hi == $openPrc || $lo == $openPrc) { foreach($arrayForDisplay as $key=>$value) { if(array_search($i, $value)) { if($row['cmd'] == $arrayForDisplay[$key]['cmd']) { $arrayForDisplay[$key]['price_counter'] += 1; $arrayForDisplay[$key]['ctr'] += $row['counter']; $arrayForDisplay[$key]['price'] += $row['open_price']; if(end($arrayForDisplay)) { $arrayForDisplay[$key]['price'] = $arrayForDisplay[$key]['price'] / $arrayForDisplay[$key]['price_counter']; } } else { $arrayForDisplay[] = array ( 'priceRow' => $i, 'price' => $row['open_price'], 'cmd' => $row['cmd'], 'ctr' => $row['counter'], 'price_counter' => 1 ); } } else { $arrayForDisplay[] = array ( 'priceRow' => $i, 'price' => $row['open_price'], 'cmd' => $row['cmd'], 'ctr' => $row['counter'], 'price_counter' => 1 ); } } } } } Link to comment https://forums.phpfreaks.com/topic/168786-how-to-fix-fatal-error-due-to-large-arrays/ Share on other sites More sharing options...
abazoskib Posted August 4, 2009 Share Posted August 4, 2009 look into the array_chunk function. you can break up a large array into pieces Link to comment https://forums.phpfreaks.com/topic/168786-how-to-fix-fatal-error-due-to-large-arrays/#findComment-890511 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.