Results 1 to 2 of 2

Thread: sum of array

  1. #1
    Hyperactive Member
    Join Date
    Nov 04
    Location
    San Isidro
    Posts
    322

    sum of array

    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. red font above.
    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.
    I want to learn more
    grace

  2. #2
    Hyperactive Member
    Join Date
    Nov 04
    Location
    San Isidro
    Posts
    322

    Re: sum of array

    Hello Please anyone?
    I want to learn more
    grace

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •