Tutorials Point


  Learning PHP
  Advanced PHP
  PHP Function Reference
  PHP Useful Resources
  Selected Reading

Copyright © 2014 by tutorialspoint



  Home     References     Discussion Forums     About TP  

PHP Function shuffle()


previous

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.

Paramters

ParameterDescription
arrayRequired. 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 following result. This result will vary everytime yoiu will shuffle an array.

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

previous Printer Friendly

Advertisements


  

Advertisements