Return to Snippet

Revision: 2254
at January 24, 2007 14:57 by jonhenshaw


Initial Code
<?php
/*
Simple randomizer.
Roger Johansson, http://www.456bereastreet.com/
*/
echo '<ul>' . "\n";
$items = array(
	1 => array(
		'href' => 'url-1',
		'title' => 'title-text-1',
		'src' => 'image-1.jpg',
		'alt' => 'alt-text-1'
	),
	2 => array(
		'href' => 'url-2',
		'title' => 'title-text-2',
		'src' => 'image-2.jpg',
		'alt' => 'alt-text-2'
	),
	3 => array(
		'href' => 'url-3',
		'title' => 'title-text-3',
		'src' => 'image-3.jpg',
		'alt' => 'alt-text-3'
	),
	4 => array(
		'href' => 'url-4',
		'title' => 'title-text-4',
		'src' => 'image-4.jpg',
		'alt' => 'alt-text-4'
	),
	5 => array(
		'href' => 'url-5',
		'title' => 'title-text-5',
		'src' => 'image-5.jpg',
		'alt' => 'alt-text-5'
	)
);
$numberOfItems = 3; // Change to the number of items you want
$randItems = array_rand($arrItems, $numberOfItems);
for ($i = 0; $i < $numberOfItems; $i++) {
	$item = $arrItems[$randItems[$i]];
	echo "\t" . '<li class="r' . ($i + 1) . '"><a href="' . $item['href'] . '" title="' . $item['title'] . '"><img src="' . $item['src'] . '" alt="' . $item['alt'] . '"></a></li>' . "\n";
}
echo '</ul>' . "\n";
?>

Initial URL
http://www.456bereastreet.com/archive/200701/simple_php_randomizer/

Initial Description
Visit the link for instructions on how to use it.

Initial Title
Simple PHP randomizer

Initial Tags
php

Initial Language
PHP