<?PHP $arr=array(1,2,3,4,5,6,7,8,9); srand((double)microtime() * 10000); shuffle($arr); foreach($arr as $element) echo "$element, "; //1, 8, 5, 4, 3, 6, 7, 9, 2, ?>
If the array is an associative array, then the values will be reshuffled.
<?PHP $arr=array("apple"=>"carbon","rice"=>"carbon","nuts"=>"fat","meat"=>"protein"); srand((double)microtime() * 10000); shuffle($arr); foreach($arr as $key=>$val) echo "$key, $val; "; //0, protein; 1, fat; 2, carbon; 3, carbon; ?>