Posted By

jonhenshaw on 08/28/07


Tagged

image random randomizer


Versions (?)

Who likes this?

6 people have marked this snippet as a favorite

basicmagic
skywalker
chakabear
LordBumpet
vali29
nebulabase


Show Random Image, File and/or HTML


 / Published in: PHP
 

This randomly displays 1 of the 5 arrays (amount of arrays to choose from can be reduced or increased)

  1. /*
  2. Inspired by
  3. Simple randomizer.
  4. Roger Johansson, http://www.456bereastreet.com/
  5. */
  6. echo '<div class="name">' . "\n";
  7. $items = array(
  8. 1 => array(
  9. 'href' => 'link.html',
  10. 'title' => 'text',
  11. 'src' => 'image-1.jpg',
  12. 'alt' => 'text'
  13. ),
  14. 2 => array(
  15. 'href' => 'link.html',
  16. 'title' => 'text',
  17. 'src' => 'image-2.jpg',
  18. 'alt' => 'text'
  19. ),
  20. 3 => array(
  21. 'href' => 'link.html',
  22. 'title' => 'text',
  23. 'src' => 'image-3.jpg',
  24. 'alt' => 'text'
  25. ),
  26. 4 => array(
  27. 'href' => 'link.html',
  28. 'title' => 'text',
  29. 'src' => 'image-4.jpg',
  30. 'alt' => 'text'
  31. ),
  32. 5 => array(
  33. 'href' => 'link.html',
  34. 'title' => 'text',
  35. 'src' => 'image-5.jpg',
  36. 'alt' => 'text'
  37. )
  38. );
  39.  
  40. $item = $items[rand(1,5)];
  41. echo "\t" . '<a href="' . $item['href'] . '" title="' . $item['title'] . '"><img src="' . $item['src'] . '" alt="' . $item['alt'] . '"></a>' . "\n";
  42. echo '</div>' . "\n";

Report this snippet  

You need to login to post a comment.