note 103872 added to function.array-rand
| From: | skyler at sixteenink dot com | Date: | Sat, 07 May 2011 22:47:34 +0000 |
| Subject: | note 103872 added to function.array-rand | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-179534@lists.php.net to get a copy of this message | ||
Alternatively, this also works.
<?php
// Array:
$input = array("one", "two", "three", "four",
"five");
// Find the number of nodes. Subtract one, to account for the first node being 0.
$maximum = count($input) -1;
// Get the random number used to output a random node
$randomArray = rand(0, $maximum);
// Results
echo $input[$randomArray];
?>
----
Server IP: 69.147.83.197
Probable Submitter: 74.220.197.138 (proxied: 74.220.197.138)
----
Manual Page -- http://www.php.net/manual/en/function.array-rand.php
Edit -- https://master.php.net/note/edit/103872
Del: integrated -- https://master.php.net/note/delete/103872/integrated
Del: useless -- https://master.php.net/note/delete/103872/useless
Del: bad code -- https://master.php.net/note/delete/103872/bad+code
Del: spam -- https://master.php.net/note/delete/103872/spam
Del: non-english -- https://master.php.net/note/delete/103872/non-english
Del: in docs -- https://master.php.net/note/delete/103872/in+docs
Del: other reasons-- https://master.php.net/note/delete/103872
Reject -- https://master.php.net/note/reject/103872
Search -- https://master.php.net/manage/user-notes.php