Jump to content

Random text load script


Zola

Recommended Posts

Hi,

 

I am wanting to create a random fact script for a small website project.

 

The idea is when the user loads a page a random fact will appear at the top ( I guess from an array of strings I will make?)

 

Can anyone recommend the most efficient and easiest way to go about this please?

Link to comment
Share on other sites

I found this code, can someone explain it a little to me please?

 


<?php
$random_text = array("Random Text 1",
                    "Random Text 2",
                    "Random Text 3",
                    "Random Text 4",
                    "Random Text 5");

$sizeof = count($random_text);
$random = (rand()%$sizeof);
print("$random_text[$random]");


?>

 

Why do we need the $sizeof and count?

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.