PHP shuffle() Function Example

PHP Script:


<?php
$sample_array = array("a" => "Samsung", "b" => "Iphone", "c" => "HTC", "d" => "Nokia", "e" => "Huawei");

shuffle($sample_array);
print_r($sample_array);
?>

Output:


Array ( [0] => Huawei [1] => Samsung [2] => HTC [3] => Iphone [4] => Nokia )

Description:

PHP shuffle() function is used to randomly reorder the elements in an array. And the existing keys of an array will be removed and new keys are assigned for the elements in an array.
This function returns TRUE on success, or FALSE on failure.

PHP shuffle() function parameters:

1- Array (Required)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s