note 106274 added to function.count
| From: | adriandotphp at gmail dot com | Date: | Mon, 24 Oct 2011 11:57:18 +0000 |
| Subject: | note 106274 added to function.count | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-184088@lists.php.net to get a copy of this message | ||
simple random value from array.
<?php
$topic=array(
"UFOs",
"Barack Obama",
"China",
"Christianity",
"Communism",
"World War II",
"Global Warming",
"Vegetarianism",
);
echo ("What do you think about ".$topic[ rand( 1,count($topic) ) ]."? ");
?>
output-->
What do you think about Global Warming? , etc
It worked fine until this output also, randomly pops up:
Notice: Undefined offset: 8 in line 100
The line 100 is:
echo ("What do you think about ".$topic[ rand( 1,count($topic) ) ]."? ");
I removed the count( $topic ) instead and replace it with this:
echo ("What do you think about ".$topic[ rand( 0,7 ) ]."? ");
and i have not encountered any error notice since.
adriandotphp@gmail.com
I'm to new to php.
----
Server IP: 69.147.83.197
Probable Submitter: 112.206.106.173
----
Manual Page -- http://www.php.net/manual/en/function.count.php
Edit -- https://master.php.net/note/edit/106274
Del: integrated -- https://master.php.net/note/delete/106274/integrated
Del: useless -- https://master.php.net/note/delete/106274/useless
Del: bad code -- https://master.php.net/note/delete/106274/bad+code
Del: spam -- https://master.php.net/note/delete/106274/spam
Del: non-english -- https://master.php.net/note/delete/106274/non-english
Del: in docs -- https://master.php.net/note/delete/106274/in+docs
Del: other reasons-- https://master.php.net/note/delete/106274
Reject -- https://master.php.net/note/reject/106274
Search -- https://master.php.net/manage/user-notes.php