PHP str_shuffle() Function: Description, Parameters, Return Value, and Examples

This article explains the PHP str_shuffle() function, detailing its purpose of randomly shuffling a string, the required string parameter, the returned shuffled string, and provides two practical code examples demonstrating its usage.

Laravel Tech Community
Laravel Tech Community
Laravel Tech Community
PHP str_shuffle() Function: Description, Parameters, Return Value, and Examples

str_shuffle() randomly shuffles a string in PHP.

Explanation: The function rearranges the characters of the given string using any possible ordering.

Parameter Description

str : The input string to be shuffled.

Return Value: The shuffled string.

Example 1:

<?php
$str = 'abcdef';
$shuffled = str_shuffle($str);
// Output: bfdaec (example output may vary)
echo $shuffled;
?>

Example 2:

<?php
echo str_shuffle("Hello World");
// Output: lolWo drHle (example output may vary)
?>
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

PHPexampleString Manipulationstr_shuffle
Laravel Tech Community
Written by

Laravel Tech Community

Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.