Reputation: 387
I have variable which is list of words separated by comma like this:
$word_list = "word1, word2, word3, word4, word5";
Word list can contain more or less words than in example above.
How to randomise $word_list
to get something like this:
word1, word5, word2, word3, word4
or
word4, word5, word3, word1, word2
Upvotes: 1
Views: 94
Reputation: 1126
You can first explode
the string into an array, then shuffle
it, and then convert it back to a string
.
Something in the lines of this:
$word_array = explode(',', $word_list);
shuffle($word_array);
$shuffeled_word_list = implode(',', $word_array);
Upvotes: 1