note 93834 modified in function.array-rand by danbrown
| From: | danbrown@php.net | Date: | Fri, 02 Oct 2009 17:13:02 +0000 |
| Subject: | note 93834 modified in function.array-rand by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-161230@lists.php.net to get a copy of this message | ||
If the array elements are unique, and are all integers or strings, here is a simple way to pick $n
random *values* (not keys) from an array $array:
<?php array_rand(array_flip($array), $n); ?>
--was--
If the array elements are unique, and are all integers or strings, here is a simple way to pick $n
random *values* (not keys) from an array $array:
array_rand(array_flip($array), $n)
http://php.net/manual/en/function.array-rand.php