note 93834 added to function.array-rand
| From: | Anonymous at osu1 dot php dot net | Date: | Fri, 02 Oct 2009 08:04:38 +0000 |
| Subject: | note 93834 added to function.array-rand | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-161215@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:
array_rand(array_flip($array), $n)
----
Server IP: 209.41.74.194
Probable Submitter: 164.67.235.138
----
Manual Page -- http://www.php.net/manual/en/function.array-rand.php
Edit -- https://master.php.net/note/edit/93834
Del: integrated -- https://master.php.net/note/delete/93834/integrated
Del: useless -- https://master.php.net/note/delete/93834/useless
Del: bad code -- https://master.php.net/note/delete/93834/bad+code
Del: spam -- https://master.php.net/note/delete/93834/spam
Del: non-english -- https://master.php.net/note/delete/93834/non-english
Del: in docs -- https://master.php.net/note/delete/93834/in+docs
Del: other reasons-- https://master.php.net/note/delete/93834
Reject -- https://master.php.net/note/reject/93834
Search -- https://master.php.net/manage/user-notes.php