Jump to content

how to fix fatal error due to large arrays


xarlotie

Recommended Posts

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
									);		
			}
		}
	}
}
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.