|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2009-12-09 08:24 UTC] jani@php.net
[2009-12-09 08:26 UTC] jani@php.net
[2009-12-09 18:28 UTC] v1d4l0k4 at gmail dot com
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Dec 04 06:00:01 2025 UTC |
Description: ------------ PHP 5.2.10 introduced a controversial BC break in array_rand() function that doesn't sort array values when the $num_req param is equal to array count. This was the most incomprehensive change I've seen in the PHP development so far. If I have a random $num_req between 1 and array count I'll need to check if I've to use array_rand() ou shuffle()? It seems so stupid... On the other hand, if this change will remain it need to be fixed anyway: there's no sense in allow array count in $num_req - it returns the array unchanged with no warnings. In this case this parameter should receive a value less than the array count. And it should be nice to have shuffle() use recommendation in the warning if $num_req is equal to array count. BTW, the manual notes about this array_rand() change is very very very incomprehensive. Reproduce code: --------------- <?php $array = range('a', 'z'); foreach (array_rand($array, count($array)) as $key) { print $array[$key]; } ?> Expected result: ---------------- MAYBE: frkzmnvuyiptdcsewbxgjqhloa Actual result: -------------- ALWAYS: abcdefghijklmnopqrstuvwxyz