Voting

: min(zero, six)?
(Example: nine)

The Note You're Voting On

HeadRoom
16 years ago
Thought I would include what I wrote to get a random image from a directory.

<?php
$image_dir
= 'images';
$count = 0;
if (
$handle = opendir($image_dir)) {
$retval = array();
while (
false !== ($file = readdir($handle))) {
if ((
$file <> ".") && ($file <> "..")) {
$retval[$count] = $file;
$count = $count + 1;
}
}

closedir($handle);
}
shuffle($retval);
$current_image = $retval[0];
?>

[NOTE BY danbrown AT php DOT net: Contains a bugfix/typofix inspired by 'ffd8' on 19-JUN-09.]

<< Back to user notes page

To Top