note 106327 deleted from function.count by danbrown
| From: | danbrown@php.net | Date: | Fri, 28 Oct 2011 00:05:55 +0000 |
| Subject: | note 106327 deleted from function.count by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-184189@lists.php.net to get a copy of this message | ||
Note Submitter: SP
----
RE: gothamxi 08-Mar-2011 06:48
Don't forget that arrays are numbered from zero. The first output in my example fixes this
issue, but actually, array_rand is a simpler solution.
<?php
$colors = array("red", "green", "blue");
echo "My favorite color is ".$colors[rand(0,count($colors)-1)]."!<br
/>\n";
echo "My favorite color is ".$colors[array_rand($colors)]."!<br />\n";
?>