note 106327 added to function.count

From: Date: Thu, 27 Oct 2011 23:52:07 +0000
Subject: note 106327 added to function.count
Groups: php.notes 
Request: Send a blank email to php-notes+get-184187@lists.php.net to get a copy of this message
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"; ?> ---- Server IP: 64.71.164.2 Probable Submitter: 38.69.9.102 ---- Manual Page -- http://www.php.net/manual/en/function.count.php Edit -- https://master.php.net/note/edit/106327 Del: integrated -- https://master.php.net/note/delete/106327/integrated Del: useless -- https://master.php.net/note/delete/106327/useless Del: bad code -- https://master.php.net/note/delete/106327/bad+code Del: spam -- https://master.php.net/note/delete/106327/spam Del: non-english -- https://master.php.net/note/delete/106327/non-english Del: in docs -- https://master.php.net/note/delete/106327/in+docs Del: other reasons-- https://master.php.net/note/delete/106327 Reject -- https://master.php.net/note/reject/106327 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#184187) next »