Shuffle String Randomly Using PHP Function

Dec 19, 2013, by admin

The str_shuffle function is used to shuffle all the characters of a string randomly. The function is mainly used for generating a random password or produce random characters for CAPTCHA validation image. Each time str_shuffle function executes and it will randomly re-shuffle the string

 

  1. <?php
  2. $str = ‘abcdef’;
  3. $shuffled = str_shuffle($str);
  4. echo “Output:”.$shuffled;
  5. ?>

Output: bfdaec