mercredi 21 décembre 2016

PHP: Outputing elements from array in a random order, before they create a specific word



I want to create an array in PHP with 4 elements in it (for example "A", "l", "e", "x") and output this letters in a random order, before they create a word "Alex", after that array should stop. So it should output something like this: Axel, leAx, xAle, ... Alex! I have found out how to output random elements from array, but it doesn't work with 4 elements for me, and I don't know how to create a loop with it.

<?php
$name = array("A","l","e","x");
$rand_keys = array_rand($name, 2);
echo $name[$rand_keys[0]];
echo $name[$rand_keys[1]];
?>

this currently outputs 2 random elements and I'm stuck here(
Please help




Aucun commentaire:

Enregistrer un commentaire