Re: [PHP4BETA] Unique Array Values
| From: | Allen Lee | Date: | Thu, 27 Apr 2000 16:01:47 +0000 |
| Subject: | Re: [PHP4BETA] Unique Array Values | ||
| References: | 1 | Groups: | php.version4 |
| Request: | Send a blank email to php-version4+get-14087@lists.php.net to get a copy of this message | ||
function distinct_array($ary)
{
if(!is_array($ary)) return 0;
$n = count($ary);
sort($ary);
$i = 1;
$d = 1;
$last = $ary[0];
$dest[0] = $ary[0];
while($i < $n)
{
if($ary[$i] != $last)
$dest[] = $ary[$i];
$last = $ary[$i];
$i++;
}
return $dest;
}
Allen Lee
Assistant Sysadmin
http://MissoulaWeb.com
Hosting, Programming and Design
On Wed, 26 Apr 2000, Andreas Pour wrote:
>
> Hi,
>
> Well, there are many undocumented functions in PHP4 -- maybe the one I'm
> looking for is lurking somewhere. I would like to retrieve all the
> unique values in an array. For example,
>
> array_values(array("cat", "dog", "mouse", "dog"))
>
> would return
>
> array("cat", "dog", "mouse")
>
> If such a function does not exist, perhaps a flag to the current
> array_values for "unique = true" is possible?
>
> Ciao,
>
> Andreas
>
> --
> PHP 4.0 Beta Mailing List <http://www.php.net/version4/>
> To unsubscribe, e-mail: php4beta-unsubscribe@lists.php.net
> For additional commands, e-mail: php4beta-help@lists.php.net
> To contact the list administrators, e-mail: php4beta-admin@lists.php.net
>
>