English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Basic PHP Tutorial

Advanced PHP Tutorial

PHP & MySQL

PHP Reference Manual

PHP shuffle() Function Usage and Example

PHP Array Function Manual

shuffle() function shuffles the order of array elements

Syntax

shuffle( $array );

Definition and Usage

This function randomly sorts the order of elements in the array.
This function assigns new keys to the elements of the array. It will delete all existing keys you may have assigned, not just rearrange the keys.

Parameter

Serial NumberParameters and Description
1

array (required)

It specifies an array.

Return Value

Returns TRUE on success, FALSE on failure.

Online Example

<?php
   $input = array("d" => "lemon", "a" => "orange", "b" => "banana");
   shuffle($input);
   print_r($input);
?>
Test to see‹/›

This will produce the following result. The result will be different each time you shuffle the array.

Array ( [0] => banana [1] => orange [2] => lemon )

PHP Array Function Manual