random string

For general web development questions that are not specifically related to CSS HTML Validator. This includes (but is not limited to) general HTML, CSS, Accessibility, JavaScript, and SEO questions.
Post Reply
maichel
Rank 0 - Newcomer
Posts: 6
Joined: Mon Oct 05, 2015 8:13 am

random string

Post by maichel »

Hello,

I have make a random string with a array. The letters A, B and C are in a array.
The letters must be see random in the browser, all three next to each other. But this doesn't work. Now the letters ABC are static in the browser and not random if you refresh the page.

Can someone help me? How can I get the letters random?

thanks in advcance.

my code is:

Code: Select all

<?php
$a=array("A","B","C");
$random_keys=array_rand($a, 3);
echo $a[$random_keys[0]];
echo $a[$random_keys[1]];
echo $a[$random_keys[2]];
User avatar
Lou
Rank V - Professional
Posts: 295
Joined: Fri Jul 29, 2005 5:55 pm
Location: CO
Contact:

Re: random string

Post by Lou »

try this

Code: Select all

<?php
$a=array("A","B","C");
shuffle($a);
echo "$a[0],$a[1],$a[2]";
?>
I find the shuffle function vary handy.
Lou
Say what you will about Sisyphus. He always has work.
Post Reply