...

View Full Version : Help randomizing image array



Evo-L
02-19-2012, 07:48 PM
Hello guys, I am after a little help here. I need to randomize an image array's order.

For example, if I have 3 images, I need them to reload each time in a different order.

Also, this is the instructions given to me on how to implement the code:

If this is PHP code, use a return statement to send your output to the block. For example:
$my_output = 'Hello, world.';
return $my_output;

My current code is HTML, and goes like this:

<div class="ad">

<a href="http://www.linkedsite.com/" target="_blank"><img src="myimagesdirectpath/img.png" alt="linkedsitename" /></a>

<br />
<a href="http://www.linkedsite.com/" target="_blank"><img src="myimagesdirectpath/img.png" alt="linkedsitename" /></a>

<br />
<a href="http://www.linkedsite.com/" target="_blank"><img src="myimagesdirectpath/img.png" alt="linkedsitename" /></a>

</div>


What I need to do is somehow turn my HTML code into a PHP code that allows the images order to be randomized, while maintaining the original instructions to "Use an output statement" to send my code to the sidebar.

Thanks! and I wish I knew more :p

Evo-L
02-20-2012, 02:26 AM
nevermind, got it.


<?php
$images = array(
'<a href="http://www.linkedsite.com/" target="_blank"><img src="myimagesdirectpath/img.png" alt="linkedsitename" /></a>',
'<a href="http://www.linkedsite.com/" target="_blank"><img src="myimagesdirectpath/img.png" alt="linkedsitename" /></a>',
'<a href="http://www.linkedsite.com/" target="_blank"><img src="myimagesdirectpath/img.png" alt="linkedsitename" /></a>'
);

shuffle($images); // Randomize images array
?>
<div class="ad">
<?php echo implode('<br />', $images); ?>
</div>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum