Re: array max min
| From: | Steve Werby | Date: | Mon, 05 Feb 2001 16:48:35 +0000 |
| Subject: | Re: array max min | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-38261@lists.php.net to get a copy of this message | ||
<rui@websolut.net> wrote:
> suppose i have a multidimensional array ex:
>
> row[monthnr][daynr][hour][numberofusers]
> row[monthnr][daynr][hour][numberofmails]
> row[monthnr][daynr][hour][numberofdownloads]
>
> the values in the array are a sql result query, soh not all of
them are
> filled like it is possible that row[12][1][23] is undefined.
>
> i need to tag the value that is maximum and minimum foreach number
of
> users, numberof mails and numberofdownloads in the same month for example,
i
You might want to try to get this info directly from an SQL query. It'll
probably be much faster than a PHP solution involving looping through each
available month and finding the max and min for 3 different keys. If you
decide to do this you'll probably want to nest "while ( list( $key, $val ) =
each( $row[$i][number..] )" type statements, but given that the key "hour"
isn't really needed you may have to transform your array and I really don't
think this solution is as elegant as using a database query.
SELECT month,
MAX(numberofusers) AS numberofusers_max,
MIN(numberofusers) AS numberofusers_min,
...,
MIN(numberofdownloads) AS numberofdownloads_min
FROM my_table
GROUP BY month
WHERE where_clause;
--
Steve Werby
COO
24-7 Computer Services, LLC
Tel: 804.817.2470
http://www.247computing.com/