Re: how to sum array items, vertically?
| From: | Siggy | Date: | Wed, 23 Jan 2002 03:33:21 +0000 |
| Subject: | Re: how to sum array items, vertically? | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-81629@lists.php.net to get a copy of this message | ||
Yeah, sorry, was posting late at night :P
I am getting time-durations from a database, aggregating them per week (with
a few conditions), so that I go from data like this:
2001-10-01, 4:30, 2 (ie, "person 2" did a "4 hour, 30 min" peice of
work on a certain date).
to this:
date = hours work by person1, person2, person3, person4 ....
2001-01-01 = 23, 45, 12, 45, 02, as in:
The reason i'm doing it in this way, is because I need to do a bit of
shifting around of hours when people worked over midnight etc.
Anyway, when I get to the end;
2001-01-01 = 23, 45, 12, 45, 02
2001-01-08 = 3, 15, 2, 35, 8
etc etc ... I want to see the total (and the average, but thats easy) hours
worked by each person.
Siggy
PS: Hey there New Zealander, hope you're in Wellington enjoying the
positively fantastic weather :P
"David Robley" <robleyd@paradise.net.nz> wrote in message
news:Xns919FA4EB8F159robleydparadisenetnz@216.92.131.4...
> 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!