note 99293 deleted from function.array-rand by salathe
| From: | salathe@php.net | Date: | Mon, 09 Aug 2010 11:06:27 +0000 |
| Subject: | note 99293 deleted from function.array-rand by salathe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-171482@lists.php.net to get a copy of this message | ||
Note Submitter: Vegard Larsen
Reason: in docs
----
PHP changed the behavior of array_rand sometime between version 5.2.6 and 5.3.2. In previous
versions, the output was shuffled, while in newer versions, it is not.
<?php
print_r(array_rand(array(0,1,2,3), 4));
?>
This used to output something like (it was random every time):
Array
(
[0] => 2
[1] => 1
[2] => 3
[3] => 0
)
In newer versions, it always outputs:
Array
(
[0] => 0
[1] => 1
[2] => 2
[3] => 3
)
This change in behavior can cause subtle bugs. Use shuffle() instead if you really want to shuffle
an array.