PHP 简单的PHP随机化器

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP 简单的PHP随机化器相关的知识,希望对你有一定的参考价值。

<?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";
?>

以上是关于PHP 简单的PHP随机化器的主要内容,如果未能解决你的问题,请参考以下文章

php HTML净化器

PHP 简单随机传递发生器

PHP简单实现一言 / 随机一句功能

基于PHP随机抽奖小程序,很简单!

php中怎样从一个数组中随机取一个元素出来呢?

php程序如何产生随机数?