note 105760 deleted from function.array-rand by danbrown

From: Date: Tue, 13 Sep 2011 14:26:05 +0000
Subject: note 105760 deleted from function.array-rand by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-183145@lists.php.net to get a copy of this message
Note Submitter: Kuuki ---- A strange behaviour occurred here at my place. I got 6 Entries in my Array and want 5 random out of these. I noticed there is always the first Element in the Random-choice as first choice {Example, i got $Array = ("kuuki", 2, 3, 4, 5, 6), array_rand($Array, 5) => always is 0, x, x, x, x as indices} Didnt test this for a large Number, in fact just pressed F5 multiple times (felt like 20) and it occurred every time. Did a small work-around, but this isnt very performant. For a Array with 6 Elements its fairly ok. Just shuffle($Array); before you use it, then the first Entry changes.

« previous php.notes (#183145) next »