dimanche 9 août 2015

How to make a variable always generate a random unique value when called in PHP?

Let's say we have this variable:

$random = substr(str_shuffle("abcdefghijklmnopqrstuvwxyz"), 0, 5);

It will generate a random string that is 5 letters long

E.g.

echo "Hi" . $random    ========  Hi qwueh

The problem with this is that only one random string is given to the variable $random. To generate a new string, you'll have to refresh the page.

Is there a way to retrieve a different, unique string every time the variable $random is called upon on the same page?

E.g.

echo "Hi" . $random    ========  Hi qwueh
echo "Hi" . $random    ========  Hi dasij
echo "Hi" . $random    ========  Hi furhf
echo "Hi" . $random    ========  Hi wuejf




Aucun commentaire:

Enregistrer un commentaire