• PHP Video Tutorials

PHP - Function shuffle()



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

Sr.No Parameter & Description
1

array(Required)

It specifies an array.

Return Value

It returns TRUE on success or FALSE on failure.

Example

Try out following example −

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

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