PHP str_shuffle() Function with Example

PHP str_shuffle() Function: Here, we will find out about the str_shuffle() work with example in PHP.

PHP str_shuffle() Function

str_shuffle() work is a string capacity and it is utilized to rearrange all characters haphazardly in the string.

At the point when this capacity executes, unequalled it returns rearranges string with irregular (characters from the given string).

Syntax:

    str_shuffle(string);
  • It acknowledges the string and returns a rearranged string.

Example:

    Input: 
    $str = "This is JustTechReview" JustTechReview
    Output:
    str_shuffle($str) = "uRetiewchveTJs"
    str_shuffle($str) = "ievRseutTwcheJ"

PHP Code:

<?php
	$str = "JustTechReview";	
	//printing shuffled string some of the times
	echo (str_shuffle($str) . "\n");
	echo (str_shuffle($str) . "\n");
	echo (str_shuffle($str) . "\n");
	echo (str_shuffle($str) . "\n");
	echo (str_shuffle($str) . "\n");

	$str = "ABC 123 @!#~&*()";	
	//printing shuffled string some of the times
	echo (str_shuffle($str) . "\n");
	echo (str_shuffle($str) . "\n");
	echo (str_shuffle($str) . "\n");
	echo (str_shuffle($str) . "\n");
	echo (str_shuffle($str) . "\n");	
?>

Output:

Output

shuevReJiTwcet
itRwseTcJeuevh
JweehRuicstTev
tewsuivhcJeTeR
itevcJTsewRueh
2~B*()@# !3A1& C
 @C&(#)12*~!3BA 
@* &2CA( !~31#)B
 B!2C1~(3@ A*&#)
&A ~3 (CB2!)@1*#

Leave a Comment

error: Alert: Content is protected!!