Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PHP shuffle() Function

PHP shuffle() Function

PHP Array ReferenceComplete PHP Array Reference Manual

Example

Shuffle the elements of an array into a random order:

Run Example »


Definition and Usage

The shuffle() function shuffles the elements of an array into a random order.

This function assigns new keys to the elements of the array; existing keys will be removed (see Example 1 below).


Syntax

shuffle(

array

)

Parameters Description
array Required. Specifies the array to use.

Technical Details

Return Value: Returns TRUE on success, FALSE on failure.
PHP Version: 4+
Changelog: Since PHP 4.2.0, the random number generator is seeded automatically.

More examples

Example 1

Shuffle the elements of an array into a random order:

"red","b"=>"green","c"=>"blue","d"=>"yellow","e"=>"purple"); shuffle($my_array); print_r($my_array); ?>

Run Example »


PHP Array ReferenceComplete PHP Array Reference Manual