random string

Discussion about any web related scripting languages like JavaScript, ASP, and PHP.
Post Reply
maichel
Rank 0 - Newcomer
Rank 0 - Newcomer
Posts: 6
Joined: Mon Oct 05, 2015 8:13 am

random string

Post by maichel » Mon Oct 12, 2015 1:30 pm

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
Rank V - Professional
Posts: 277
Joined: Fri Jul 29, 2005 5:55 pm
Location: CO
Contact:

Re: random string

Post by Lou » Mon Oct 12, 2015 7:37 pm

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