Justtechjobs.com Find a programming school near you






Online Campus Both


php4-beta | 200004

Re: [PHP4BETA] Unique Array Values From: Allen Lee (vandal <email protected>)
Date: 04/27/00

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 <email protected>
> For additional commands, e-mail: php4beta-help <email protected>
> To contact the list administrators, e-mail: php4beta-admin <email protected>
>
>

-- 
PHP 4.0 Beta Mailing List <http://www.php.net/version4/>
To unsubscribe, e-mail: php4beta-unsubscribe <email protected>
For additional commands, e-mail: php4beta-help <email protected>
To contact the list administrators, e-mail: php4beta-admin <email protected>