note 115710 added to function.array-rand
| From: | marco at behnke dot biz | Date: | Fri, 12 Sep 2014 01:52:24 +0000 |
| Subject: | note 115710 added to function.array-rand | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-200421@lists.php.net to get a copy of this message | ||
Is there a difference in randomness if you use shuffle instead?
<?php
function array_shuffle($input, $num_of_results) {
shuffle($input);
return array_chunk($input, $num_of_results, true)[0];
}
$input = array("Neo", "Morpheus", "Trinity", "Cypher",
"Tank");
var_dump(array_shuffle($input, 2));
/*
array(2) {
[0]=>
string(3) "Neo"
[1]=>
string(8) "Morpheus"
}
*/
?>
And yes, I know that my example returns a portion of the array and not just the key numbers
----
Server IP: 93.124.244.82
Probable Submitter: 148.122.56.106
----
Manual Page -- http://php.net/manual/en/function.array-rand.php
Edit -- https://master.php.net/note/edit/115710
Del: integrated -- https://master.php.net/note/delete/115710/integrated
Del: useless -- https://master.php.net/note/delete/115710/useless
Del: bad code -- https://master.php.net/note/delete/115710/bad+code
Del: spam -- https://master.php.net/note/delete/115710/spam
Del: non-english -- https://master.php.net/note/delete/115710/non-english
Del: in docs -- https://master.php.net/note/delete/115710/in+docs
Del: other reasons-- https://master.php.net/note/delete/115710
Reject -- https://master.php.net/note/reject/115710
Search -- https://master.php.net/manage/user-notes.php