On 30/04/2004, at 12:06 PM, John W. Holmes wrote:

Although this begs the question of why you'd need to "rekey" an array...

It seemed the easiest way to get the first two elements off the beginning of the array after shuffle()ing it, or so I thought -- but I'm more than happy to hear of a better way, as always :)


My only requirement is really to end up with an array named $files that can be used later on in the template in a foreach loop.

<?
shuffle($filenames);                                    // random sort
$filenames = array_values($filenames);  // re-key
for($i=0;$i<2;$i++) {
        $files[] = "path/to/".$filenames[$i];
        }
?>

... then in the template:

<? foreach($files as $file): ?>
        <div ...>
                ...
                <? include($file); ?>
                ...
        </div>
<? endforeach; ?>


Like I said, always happy to see something in a few less lines :)


---
Justin French
http://indent.com.au

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to