랜덤이미지배너
본문
이렇게 하면 되는건가요?
<div>
<script>
var banners = new Array() ;
banners[0] = '<div><a href="" target="_blank" /><img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQKTJek6_ge5gp3UXM9OhsHf9h_AauxXhIhFg&usqp=CAU" border="0" /></a></div>' ;
banners[1] = '<div><a href="" target="_blank" /><img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTYZAAiEM-pyCUHD7jUdfzv75D0pdvwCpJ7UQ&usqp=CAU" border="0" /></a></div>' ;
banners[2] = '<div><a href="" target="_blank" /><img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSbdo-yC0Z-hXyx1-ep1Rn1KWau0BkSU4qw6Q&usqp=CAU" border="0" /></a></div>' ;
banners[3] = '<div><a href="" target="_blank" /><img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSW4XHAc_3e_m2S-bQFIjgrCWWSIfOCKrCDOw&usqp=CAU" border="0" /></a></div>' ;
banners[4] = '<div><a href="" target="_blank" /><img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcScIGatWRvdQvQ74YXqMuIZlw8zIHt0uaz0iA&usqp=CAU" border="0" /></a></div>' ;
banners[5] = '<div><a href="" target="_blank" /><img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRhg8TwksDw03khK8X87Tgs7AfWNPsGMYQbRA&usqp=CAU" border="0" /></a></div>' ;
banners[6] = '<div><a href="" target="_blank" /><img src="/web/img/vip_06.jpg" border="0" /></a></div>' ;
var bannerReq = new Array() ;
var theOne ;
var z=0 ;
for (i=0; i<banners.length; i++){
bannerReq[i] = i ;
while (z<banners.length){
theOne = Math.floor(Math.random()*banners.length) ;
if (banners[theOne]!="_selected!") {
document.write(banners[theOne]) ;
banners[theOne] = "_selected!" ;
z++ ;
}
}
}
</script>
</div>
답변 1
아래 코드 활용해 간단히 만들어 보세요.
<?php
$arr = [1,2,3];
shuffle($arr);
foreach($arr as $v) {
echo $v."<br>";
}