note 13719 added to function.array-unique.php
| From: | info at phpcoding dot net | Date: | Fri, 29 Jun 2001 19:03:53 +0000 |
| Subject: | note 13719 added to function.array-unique.php | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-14774@lists.php.net to get a copy of this message | ||
Following function returns an array containing unique random numbers. In my opinion a nice way of
using array_unique:
function rand_numbers($min,$max,$item_nbr)
{
$return_array = array();
while (count($return_array)<$item_nbr)
{
$return_array[] = rand($min,$max);
$return_array = array_unique($return_array);
}
return $return_array;
}
$min and $max set the range for the rand() function. Use $item_nbr to tell the function how many
random, unique numbers you want.
(Feedback is appreciated)
http://www.php.net/manual/en/function.array-unique.php