Patrioticcow
Patrioticcow

Reputation: 27048

php go to random links how to?

i have a link:

<a href="">Click Me!</a>

and i have a few links: google.com, yahoo.com, etc...

what i want is each time i click on the Click Me! to grab a random link and go to it

any ideas? thanks

Upvotes: 0

Views: 174

Answers (1)

user142162
user142162

Reputation:

You can make use of array_rand to pick out a random item from an array:

$urls = array('http://google.com', 'http://yahoo.com');
echo '<a href="' . $urls[array_rand($urls)] . '">Click Me!</a>';

Upvotes: 4

Related Questions