Re: how to sum array items, vertically?

From: Date: Wed, 23 Jan 2002 03:10:47 +0000
Subject: Re: how to sum array items, vertically?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-81627@lists.php.net to get a copy of this message
sigurd@totallydigital.co.nz (Sigurd) wrote in news:20020122132816.75505.qmail@pb1.pair.com: > Assuming my array of this variety: > > array( > "Monday" => 1, 4, 1, 0, > "Tuesday" => 5, 0, 0, 0, > "Sunday" => 2, 2, 3, 1); > > How do I sum, vertically, the numbers; short of traversing thru the > array and doing it manually ? I thought about doing a array_flip() but > that didnt work. I want this: > > array( > 1 => 7, > 2 => 6, > 3 => 4, > 4 => 1); > > Siggy Presume you mean 1=>8 or are you using a real early pentium? From whence are you populating this array? If it comes from a database it might be an option to sum/group the data as you extract it and let the DB do the dirty work. Cheers -- David Robley Temporary Kiwi!

« previous php.general (#81627) next »