Goof Productions
Slogans

Two of the slogans for Goof Productions is - the best way to waste time and - always a source of fun. At the 10th of February there was five slogans, and the slogans shows up at random under the header. This is done by using PHP array and the function mt_rand().

The slogans is from the definition of goof:

  • Verb: To waste or kill time; evade work or responsibility.
  • Noun: A source of fun or cause for amusement.

As long as you can use PHP, it is pretty easy to make random text appear on your page. First you need to define an array with some values. Second and last, you’ll need to include the array in the html, with the key as a random value within the length of the array. The code:

<?php
$a2e = array("A", "B", "C", "D","E");
echo 'A random text generator in php: '.$a2e[mt_rand(0, count($a2e)-1)];
?>

Define an array and add some values. The echo will print out text on the screen, so make sure it is a html valid text. To print out a single value from the array, it needs a key. In this example, all the letters have a key between 0 and 4, this is because all arrays starts with 0, unless otherwise specified. I use mt_rand() to generate a random int, between 0 and the length of my array-1. The count() function, will count the number of values in my array, but unlike array, it will start on one. So the array has keys from 0 - 4, but count() will count the keys from 1 - 5. So after the count() function, I’ve added a -1.

If you wish to specify the array keys, you can do it like this:

$a2e = array(1 => "A", 2 => "B", 3 => "C", 4 => "D", 5 => "E");

Just remember that if you start keys on 1, instead of 0, remove the -1 after count(), since your keys now goes from 1-5 instead of 0-4.

php.net is a very good page to look up php functions, and w3schools.com is a very good page to start learning html5 and php. The php functions used in this example and more reading for you: