sum of array

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
acellec
php-forum Active User
php-forum Active User
Posts: 26
Joined: Thu May 17, 2012 5:44 pm

Thu Aug 23, 2012 4:30 pm

i have my code below
for ($x = 1; $x <= 29; $x++)
{
$SQLstringx=QueryDBSumV('tbl'.$depttable[$x],$from,$to);
$queryx = mysql_query($SQLstringx) or die("Fatal error: ".error_reporting(0));

$count = mysql_num_rows(mysql_query($SQLstringx));

if ($count > 0) {
$setx=array();

while ($recordx = mysql_fetch_object($queryx)) {
$setx[$recordx->starperiod][]= $recordx;

}
ksort($setx);

$headeralloc=array();
$headerutil=array();
$headerproj=array();
$headeract=array();

foreach ($setx as $headerkey=> $headervalue) {
foreach ($headervalue as $headerrecords) {

$mono=$headerrecords->qrtcode;
$sno= remove_non_numeric($mono);
$monumber=substr($sno,0,-4);
$headeralloc[$monumber]=$headerrecords->sumtotalalloc;
$headerutil[$monumber]=$headerrecords->sumtotalutil;
$headerproj[$monumber]=$headerrecords->sumtotalip;
$headeract[$monumber]=$headerrecords->sumtotalia;

}

}
print_r($headeralloc);

}

}
when i check the result of the array $headeralloc.
i have
Array ( [8] => 2524794870.04 ) Array ( [7] => 555608878.54 [8] => 0.63 )
my problem is in my code. how can i sum same array keys. like for the above array 8 and retain 7.

thanks.
acellec
php-forum Active User
php-forum Active User
Posts: 26
Joined: Thu May 17, 2012 5:44 pm

Thu Aug 23, 2012 9:44 pm

my second post i hope someone will hep :(
Post Reply