X
HOME HTML5 CSS3 JAVASCRIPT SQL PHP5 JQUERY ANGULAR BOOTSTRAP3 XML MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

PHP shuffle() Function

PHP Array Reference PHP Array Reference

Example

Randomize the order of the elements in the array:

<?php
$my_array = array("red","green","blue","yellow","purple");

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

Run example »

Definition and Usage

The shuffle() function randomizes the order of the elements in the array.

This function assigns new keys for the elements in the array. Existing keys will be removed (See Example 1 below).


Syntax

shuffle(array)

Parameter Description
array Required. Specifies the array to use

Technical Details

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


More Examples

Example 1

Randomize the order of the elements in the array:

<?php
$my_array = array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow","e"=>"purple");

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

Run example »


PHP Array Reference PHP Array Reference

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB HOSTING

UK Reseller Hosting

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates

SHARE THIS PAGE

facebook