samedi 2 mars 2019

Random value in an given ARRAY?

I have written the below code to find a random value in an array.

function generateRandomString($length = 1) {
    return substr(str_shuffle(str_repeat($x='GXYZ', ceil($length/strlen($x)) )),1,$length);
}

$numbers_rev = array("1","2","3","4","5","6","7","8","9","0","."); 
$letter_rev = array("A","L","B","E","R","T","O","I","N",generateRandomString(),"/");    

$phrase_rev = "5000";

echo $rev = str_replace($numbers_rev,$letter_rev,$phrase_rev); 

It gives an output as: RXXX or RZZZ or RYYY or RGGG

I am expecting the output: RZGXZ

Help please, thanks




Aucun commentaire:

Enregistrer un commentaire