Re: Random Includes - A Good Scheme
| From: | Philip Olson | Date: | Tue, 02 Jan 2001 22:02:52 +0000 |
| Subject: | Re: Random Includes - A Good Scheme | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-32376@lists.php.net to get a copy of this message | ||
Here's one way to do it :
<?php
function randInclude($dir='./') {
srand ((double) microtime() * 10000000);
$fd = opendir($dir);
while ($part = readdir($fd)) {
if ($part != "." && $part != "..") {
clearstatcache();
$files[] = $part;
}
}
// array_rand choose two random keys
$key = array_rand($files,2);
include $files[$key[0]];
include $files[$key[1]];
}
// assuming includes are in include dir
randInclude('./include');
?>
Regards,
Philip
On Tue, 2 Jan 2001, JB wrote:
> Hey,
>
> I'm wondering if any of you happen to know of a good scheme to include multiple files
> randomly.
>
> IE- I have a list of say 5 include files. I want my script to randomly select 2 of them.
>
> What would be even better would be a peice of code the goes to a certain directory and randomly
> includes 1 or 2 files that are in the directory.
>
> Thanks!
>
> Jason
>