note 105760 added to function.array-rand

From: Date: Mon, 12 Sep 2011 23:12:39 +0000
Subject: note 105760 added to function.array-rand
Groups: php.notes 
Request: Send a blank email to php-notes+get-183121@lists.php.net to get a copy of this message
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. ---- Server IP: 212.124.37.9 Probable Submitter: 79.234.208.186 ---- Manual Page -- http://www.php.net/manual/en/function.array-rand.php Edit -- https://master.php.net/note/edit/105760 Del: integrated -- https://master.php.net/note/delete/105760/integrated Del: useless -- https://master.php.net/note/delete/105760/useless Del: bad code -- https://master.php.net/note/delete/105760/bad+code Del: spam -- https://master.php.net/note/delete/105760/spam Del: non-english -- https://master.php.net/note/delete/105760/non-english Del: in docs -- https://master.php.net/note/delete/105760/in+docs Del: other reasons-- https://master.php.net/note/delete/105760 Reject -- https://master.php.net/note/reject/105760 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#183121) next »