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 ?
- PHP | key() Function
- p5.js | nfp() Function
- PHP | Ds\Map get() Function
- p5.js | nfs() Function
- D3.js now() function
- p5.js | nfc() function
- PHP | pos() Function
- CSS | url() Function
- PHP | end() Function
- CSS env() Function
- PHP | Ds\Map xor() Function
- PHP | Ds\Map put() Function
- PHP | ord() Function
- PHP | each() Function
- PHP | Ds\Set xor() Function
- D3.js | d3.map.set() 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.