note 38438 added to function.array-rand

From: Date: Sun, 21 Dec 2003 09:28:56 +0000
Subject: note 38438 added to function.array-rand
Groups: php.notes 
Request: Send a blank email to php-notes+get-62289@lists.php.net to get a copy of this message
array_rand() seems to be broken, at least in 4.3.1. I fought it for several hours, until just doing this instead: $selected = $ida[rand(0,count($ida)-1)]; $selected is the singular answer I was looking for, and $ida is the array I was working with. If you're looking for a singular answer, this is the easiest way. Replace $ida with your array of values you're looking for, and $selected will be your singular answer. Hope this helps for someone. Don't spend hours on array_rand() like I did. ---- Manual Page -- http://www.php.net/manual/en/function.array-rand.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+38438 Delete -- http://master.php.net/manage/user-notes.php?action=delete+38438&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+38438&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#62289) next »