note 28974 added to function.file
| From: | dosn at n-net dot org | Date: | Wed, 29 Jan 2003 15:23:32 +0000 |
| Subject: | note 28974 added to function.file | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-43075@lists.php.net to get a copy of this message | ||
refering to the comment of omar dot speranza at argomedia dot it:
---------
$line = mt_rand(0,count($file));
echo $file[$line];
---------
count gives the number of elements $file contains.
The first element of the array is $file[0].
The last element is $file[(count($file)-1)].
If the value created by mt_rand is count($file), $file($line) is empty.
So the above doesn't work correctly.
To avoid getting an empty string, you should use this:
$line = mt_rand(0, (count($file)-1));
--
http://www.php.net/manual/en/function.file.php
http://master.php.net/manage/user-notes.php?action=edit+28974
http://master.php.net/manage/user-notes.php?action=delete+28974
http://master.php.net/manage/user-notes.php?action=reject+28974