Don't like ads? PRO users don't see any ads ;-)
Guest

random facts

By: a guest on Aug 10th, 2012  |  syntax: None  |  size: 0.43 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2. function array_random($arr, $num = 1) {
  3.     shuffle($arr);
  4.    
  5.     $r = array();
  6.     for ($i = 0; $i < $num; $i++) {
  7.         $r[] = $arr[$i];
  8.     }
  9.     return $num == 1 ? $r[0] : $r;
  10. }
  11.  
  12. $a = array("Welcome to HRS!",
  13. "Type in fact here",
  14. "Type in fact here",
  15. "Type in fact here",
  16. "Type in fact here",
  17. "Type in fact here",
  18. "Type in fact here",
  19. "Etc.......",
  20. "written by duardo");
  21. print_r(array_random($a));
  22. ?>