downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
search for in the  

<rsortsizeof>
Last updated: Thu, 26 Jun 2008

shuffle

(PHP 4, PHP 5)

shuffle — Shuffle an array

Description

bool shuffle ( array &$array )

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

Parameters

array

The array.

Return Values

Returns TRUE on success or FALSE on failure.

Examples

Example #1 shuffle() example

<?php
$numbers
= range(1, 20);
srand((float)microtime() * 1000000);
shuffle($numbers);
foreach (
$numbers as $number) {
   echo
"$number ";
}
?>

Notes

Note: This function assigns new keys to the elements in array . It will remove any existing keys that may have been assigned, rather than just reordering the keys.

Note: As of PHP 4.2.0, there is no need to seed the random number generator with srand() or mt_srand() as this is now done automatically.



add a noteadd a note User Contributed Notes
Shuffle an array
There are no user contributed notes for this page.




<rsortsizeof>
Last updated: Thu, 26 Jun 2008
show source | credits | sitemap | contact | advertising | mirror sites
Copyright © 2001-2005 The PHP Group
All rights reserved.
This unofficial mirror is operated at: http://phpbuilder.com/
Last updated: Tue Nov 1 20:20:59 2005 EST
Columns / Articles | Tips / Quickies | News | News Linking and RSS Feeds | Shared Code Library
Mail Archives | Support / Discussion Forums | Get Started! Links | Contribute! | Docs