"Pieter From Sa" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Hi all
>
> I have data in one field in a database, all is numbers that can be
> duplicated.
>
> 200, 200, 100, 50, 30.
>
> i need to get all data from this field, terminate the duplicates and get
the
> max nuber that is not a duplicate, in the numbers above that would be 100.
>
> I had a look at array_unique, but i'm not sure if this is the right
function
> for this.
>
> Thanks in advance.

Hi,

setup your array starting with the highest values:

$array = array(200, 200, 100, 50, 30);

Then use array_count_values($array). This will give you an associative array
where the key is the former value and the value is the number of the
occurrences. In your case this would be:

array(200 => 2, 100 => 1, 50 => 1, 30 => 1);

Then loop through the array with foreach() and check each element for the
value 1. When you have found the first array element with a value of 1 exit
from the loop with break.

Hope this works for you.

Regards, Torsten Roehr

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to