The str_shuffle() function is an inbuilt function in PHP and is used to randomly shuffle all the characters of a string passed to the function as a parameter. When a number is passed, it treats the number as the string and shuffles it. This function does not make any change in the original string or the number passed to it as a parameter. Instead, it returns a new string which is one of the possible permutations of the string passed to it in the parameter.
Parameter: This function accepts a single parameter $string. The parameter $string specifies the string whose characters are needed to be shuffled. In place of a string, a number can also be passed. If a number is passed instead of a string as a parameter then this function will treat that number as a string.
Return Value: The function returns a string of the same length but with shuffled characters within itself. Every time the program is executed, it displays a different output since shuffling of characters is different every time. The original string or the number can be the return value on some occasions.
Input : $string = "raj" Output : jar Input : $string = "geeks" Output : eeksg Input : $string = 142 Output : 412 Note: The output will be different on every execution.
Below programs illustrate the str_shuffle() function:
Program 1: Program to demonstrate the str_shuffle() fucntion when a string is passed.
Program 2: Program to demonstrate the str_shuffle() fucntion when a number is passed.
- p5.js | nfs() Function
- p5.js | sq() function
- p5.js | nfp() Function
- PHP Ds\Set sum() Function
- PHP | max( ) Function
- PHP | min( ) Function
- p5.js | day() function
- p5.js | nfc() function
- p5.js | nf() Function
- p5.js | pow() function
- PHP | pow( ) Function
- PHP | Ds\Map map() Function
- PHP | Ds\Map last() Function
- PHP | Ds\Map put() Function
- PHP | Ds\Set xor() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.