This function randomizes the order of the elements in an array also used together with srand() function.
shuffle() example:
$ar_value = range('A','F'); // create and fill the elements of $sar_value = array('A','B',...'F');
echo "First value:
\n”;
WHILE(list($key,$value) = each($ar_value)){
echo “Index[ {$key} ] => $value
\n”;
}
echo “
\n”;
echo “After shuffle():
\n”;
srand((float)microtime()*1000000);
shuffle($ar_value);
WHILE(list($key,$value) = each($ar_value)){
echo “Index[ {$key} ] => $value
\n”;
}
?>
And the result of the code above:
First value:
Index[ 0 ] => A
Index[ 1 ] => B
Index[ 2 ] => C
Index[ 3 ] => D
Index[ 4 ] => E
Index[ 5 ] => F
After shuffle():
Index[ 0 ] => C
Index[ 1 ] => B
Index[ 2 ] => A
Index[ 3 ] => F
Index[ 4 ] => D
Index[ 5 ] => E
RSS feed for comments on this post · TrackBack URI
Leave a reply