A Simple PHP image rotator
This has probably been done a thousand times over by many programmers, but I thought I'd offer just one more to the collection.
Three Simple Steps
PHP: Function randomImage
<?php
function randomImage ( $array ) {
$total = count($array);
$call = rand(0,$total-1);
return $array[$call];
}
?>
The Image Array
<?php
$my_images = array (
"dustin.jpg",
"Jeffrey.jpeg",
"Chrissy.png",
"Kristen.gif"
);
?>
The embedded PHP into your XHTML:
<?php
echo '<img
src="'.randomImage($my_images).'"
alt="Random Image" />';
?>
Why did I bother writing this? Because I've seen way too many scripts and downloads and all that yada yada just to make some simple random image rotator.
If you want to add more images, just put in an extra item into the array.
Case closed.
recent
- Matador: The Obvious MVC Framework for Node
- Sandboxing JavaScript
- Crouching Ender, hidden command
- Ender.js - The open submodule library
- Qwery - The Tiny Selector Engine
- Klass
- Smallest DOMReady code, ever.
- $script.js - Another JavaScript loader
- About that slowness on Twitter...
- Autocomplete Fuzzy Matching
- JavaScript Cache Provider
- JavaScript Animate
- Asynchronous method queue chaining in JavaScript
- Something changed
- Unofficial Twitter Widget Documentation
i am dustin diaz

