September 2001
Intermediate to advanced
768 pages
32h 45m
English
bool shuffle(array array) Randomizes the order of elements in an array.
Returns:
TRUE on success; FALSE on failure
Description:
Randomizes the order of elements in an indexed array. Use srand() to seed the randomizer before calling this function. If you pass an associative array to this function, it randomizes the values but destroys the keys.
After shuffling, array is numerically indexed starting from 0.
Version:
PHP 3 since 3.0.8, PHP 4 since 4.0b4
See also:
array_rand() rand() srand()
Example:
$numbers = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
srand(time());
echo "Before: ", implode(", ", $numbers), "\n";
shuffle($numbers);
echo "After: ", implode(", ", $numbers), "\n";
Output: Before: 1, 2, 3, ... |
Read now
Unlock full access