note 106274 deleted from function.count by danbrown
| From: | danbrown@php.net | Date: | Mon, 24 Oct 2011 16:00:12 +0000 |
| Subject: | note 106274 deleted from function.count by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-184101@lists.php.net to get a copy of this message | ||
Note Submitter: adriandotphp at gmail dot com
----
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.