Re: Min and max of array
| From: | Kevin Stone | Date: | Fri, 07 Mar 2003 19:43:04 +0000 |
| Subject: | Re: Min and max of array | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-138687@lists.php.net to get a copy of this message | ||
----- Original Message -----
From: "Liam Gibbs" <liamgibbs@sympatico.ca>
To: "php list" <php-general@lists.php.net>
Sent: Friday, March 07, 2003 12:24 PM
Subject: Re: [PHP] Min and max of array
> >you can sort it and get the values.
>
> I would, but I need the array in the same order. I can't sort it.
>
>
> -- ------------------
So what you really need is the min/max value of alpha numeric values in an
array? Well then here you go. This is the second function that I've given
away today. I hope it does what you need..
function max_alpha($array)
{
if (!is_array($array))
return false;
foreach($array as $key => $val)
{
if(!isset($prev_val))
$max_val = '';
$result = strcmp($val, $max_val);
if ($result > 0) // < for min value
{
$max_val = $val;
}
}
return $max_val;
}
- Kevin