PHP - Function shuffle()


Advertisements


Syntax

shuffle( $array  );

Definition and Usage

This function shuffles (randomizes the order of the elements in) an array.

This function assigns new keys for the elements in array. It will remove any existing keys you may have assigned, rather than just reordering the keys.

Parameters

Parameter Description
array Required. Specifies an array.

Return Value

Returns TRUE on success or FALSE on failure.

Example

Try out following example −

<?php
   $fruits = array("d"=>"lemon", "a"=>"orange", "b"=>"banana" );
   shuffle($fruits);
   
   print_r($fruits);
?> 

This will produce the following result. This result will vary everytime you will shuffle an array.

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

php_function_reference.htm

Advertisements