次のスクリプトは私のニーズに最適ですが、残念ながら重複した画像が頻繁に表示されます。
この問題を修正するにはどうすればよいですか?
または、これの代わりに、ランダムな画像を1つの列に表示し、それぞれに独自のリンクを表示できる同様のスクリプトがありますか?
ありがとう。
<?php
function display_random_img($array) {
$key = rand(0 , count($array) -1);
$link_url = $array[$key]['url'];
$alt_tag = $array[$key]['alt'];
$random_img_url = $array[$key]['img_url'];
list($img_width, $img_height) = getimagesize($random_img_url);
return "<a href=\"$link_url\"><img src=\"$random_img_url\" width=\"$img_width\" height=\"$img_height\" alt=\"$alt_tag\" /></a>";
}
//-----------------------
$ads_array = array(
array(
'url' => 'http://www.mysite.com/',
'alt' => 'Image1',
'img_url' => 'http://www.mysite.com/pic1.jpg'
),
array(
'url' => 'http://www.yoursite.com/',
'alt' => 'Image2',
'img_url' => 'http://www.mysite.com/pic2.jpg'
),
array(
'url' => 'http://www.theirsite.com/',
'alt' => 'Image3',
'img_url' => 'http://www.mysite.com/pic3.jpg'
)
);
//-----------------------
$ads_array_1 = array(
array(
'url' => 'http://www.mysite.com/',
'alt' => 'Image1',
'img_url' => 'http://www.mysite.com/pic1.jpg'
),
array(
'url' => 'http://www.yoursite.com/',
'alt' => 'Image2',
'img_url' => 'http://www.mysite.com/pic2.jpg'
),
array(
'url' => 'http://www.theirsite.com/',
'alt' => 'Image3',
'img_url' => 'http://www.mysite.com/pic3.jpg'
)
);
//-----------------------
$ads_array_2 = array(
array(
'url' => 'http://www.mysite.com/',
'alt' => 'Image1',
'img_url' => 'http://www.mysite.com/pic1.jpg'
),
array(
'url' => 'http://www.yoursite.com/',
'alt' => 'Image2',
'img_url' => 'http://www.mysite.com/pic2.jpg'
),
array(
'url' => 'http://www.theirsite.com/',
'alt' => 'Image3',
'img_url' => 'http://www.mysite.com/pic3.jpg'
)
);
//-----------------------
echo display_random_img($ads_array);
echo display_random_img($ads_array_1);
echo display_random_img($ads_array_2);
?>