neilgee
5/16/2016 - 4:24 AM

Output a Random String from an Array in PHP

Output a Random String from an Array in PHP

<?php
// http://php.net/manual/en/function.array-rand.php
$slogans = array(
  "Where friendships flourish and grow",
  "Where you are treated with respect",
  "Where people are helpful and sincere",
  "Where you feel safe and at home"
  );

echo '<p>' . $slogans[array_rand($slogans)] . '</p>';  
//array_rand is applied to the array of $slogans which picks out the one string which is echo'ed

?>