Shuffle characters with PHP

  1. Home
  2. Knowledge Base
  3. PHP
  4. Shuffle characters with PHP

Shuffle characters with PHP

A rather fun function you can use is str_shuffle( ). What this does is to shuffle all the characters in a string. You can use this to create a quick anagram programme. Try this script:

<?PHP

$full_name = 'anagram';

$full_name = str_shuffle($full_name);

print $full_name;

?>

Only three lines long, but the function takes a variable or direct text and shuffles the characters around.

 

Facebook Comments

Was this article helpful?

Related Articles