note 114972 added to function.array-rand
| From: | john at brahy dot com | Date: | Wed, 07 May 2014 23:00:43 +0000 |
| Subject: | note 114972 added to function.array-rand | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-199480@lists.php.net to get a copy of this message | ||
if you want random elements from an array, this worked pretty well for me.
<?php
//using shuffle randomizes the order of elements
function get_random_elements( $array,$limit = 0 ) {
shuffle($array);
if ( $limit > 0 ) {
$array = array_splice($array, 0, $limit);
}
return $array;
}
?>
----
Server IP: 72.52.91.14
Probable Submitter: 74.61.100.197
----
Manual Page -- http://php.net/manual/en/function.array-rand.php
Edit -- https://master.php.net/note/edit/114972
Del: integrated -- https://master.php.net/note/delete/114972/integrated
Del: useless -- https://master.php.net/note/delete/114972/useless
Del: bad code -- https://master.php.net/note/delete/114972/bad+code
Del: spam -- https://master.php.net/note/delete/114972/spam
Del: non-english -- https://master.php.net/note/delete/114972/non-english
Del: in docs -- https://master.php.net/note/delete/114972/in+docs
Del: other reasons-- https://master.php.net/note/delete/114972
Reject -- https://master.php.net/note/reject/114972
Search -- https://master.php.net/manage/user-notes.php