Scripting 随机图像作为与图像关联的链接

Scripting 随机图像作为与图像关联的链接,scripting,random,Scripting,Random,我正在寻找一个脚本,它将调用一个随机图像链接到pageload上相应的站点。有人知道javascript或php实现这一点的方法吗 <?php $random = array( array('image' => 'http://example.com/image1.jpg', 'url' => 'http://example1.com/'), array('image' => 'http://example.com/image2.jpg', 'url' =&g

我正在寻找一个脚本,它将调用一个随机图像链接到pageload上相应的站点。有人知道javascript或php实现这一点的方法吗


<?php

$random = array(
  array('image' => 'http://example.com/image1.jpg', 'url' => 'http://example1.com/'),
  array('image' => 'http://example.com/image2.jpg', 'url' => 'http://example2.com/'),
  array('image' => 'http://example.com/image3.jpg', 'url' => 'http://example3.com/'),
  array('image' => 'http://example.com/image4.jpg', 'url' => 'http://example4.com/'),
);

$current = rand(0, count($random) - 1);
print "<a href=\"" . $random[$current]['url'] . "\"><img src=\"" . $random[$current]['image'] . "\" alt=\"\" /></a>\n";

?>
又快又容易。这可能不是最好的方法——我个人会将它挂接到数据库而不是静态数组中——但它会让您在几秒钟内启动并运行