ADVERTISEMENT
ADVERTISEMENT

Home » PHP

PHP str_shuffle() Function with Example

PHP str_shuffle() Function: Here, we are going to learn about the str_shuffle() function with example in PHP.
Submitted by IncludeHelp, on February 05, 2019

PHP str_shuffle() Function

str_shuffle() function is a string function and it is used to shuffle all characters randomly in the string.

When this function executes, all time it returns shuffles string with random characters (characters from the given string).

Syntax:

    str_shuffle(string);

It accepts the string and returns shuffled string.

Examples:

    Input: 
    $str = "This is IncludeHelp"
    Output:
    str_shuffle($str) = "enHeIdcupll"
    str_shuffle($str) = "IcduneeplHl"

PHP code:

<?php
	$str = "IncludeHelp";	
	//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

enHeIdcupll
IcduneeplHl
eenulHpcIld
enucIHepdll
ldIlceeupHn
2~B*()@# !3A1& C
 @C&(#)12*~!3BA 
@* &2CA( !~31#)B
 B!2C1~([email protected] A*&#)
&A ~3 (CB2!)@1*#
ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.