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.
- How to get the function name inside a function in PHP ?
- D3.js | d3.hsl() Function
- PHP | exp() Function
- PHP | max( ) Function
- PHP | min( ) Function
- p5.js | min() function
- PHP | ord() Function
- p5.js | second() function
- p5.js | pan() Function
- PHP Ds\Map sum() Function
- p5.js | max() function
- D3.js | d3.map.has() Function
- D3.js | d3.map.get() 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 email@example.com. 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.