Re: adding in array

From: Date: Tue, 10 Dec 2002 11:37:15 +0000
Subject: Re: adding in array
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-23995@lists.php.net to get a copy of this message
Hi, I'ld suggest this: // inside your loop $array[$year] += $value; HTH, Bastian Martin Allan Jensen schrieb: > Hi all, > > I have a problem i know you can help me with. > > I have this flushet out from a loop command: > Year: 2000 & ID: 14 & Value: 300 > Year: 2002 & ID: 11 & Value: 640 > Year: 2002 & ID: 10 & Value: 100 > Year: 2003 & ID: 11 & Value: 200 > Year: 2004 & ID: 11 & Value: 150 > Year: 2005 & ID: 11 & Value: 250 > > I need PHP to put it into an array, but if it's the same YEAR the it's supposed to > add the two values, so if i made a flush of the arrayt it would say somthing like: > Array( [0] => Array ( [2000] => "300") [1] => Array( [2002] => > "740" ) [2] => Array( [2003] => "200") [4] => Array( [2004] => > "150") [5] => Array( [2005] => "250")) > > So here is the little plan, > I only got the values in a variable in a loop, so i guess firstly putting it into an array > could be a good idea, then add it and put it into an array again so i can flush the output, but > i'm really bad at array (and english) so i really hope that you will help me. > > I hope you get it, Thanks A lot for your help !! > > BEST Regards, > Martin Allan Jensen

« previous php.db (#23995) next »