function array_shuffle($array) { //不是数组 if(!is_array($array)) { return array(); } //如果为空或者只有1项 if(($count=count($array)) return $array; } //得到打乱的键 $rand_keys = array_rand($array, count($array)); $newArr=array(); foreach($rand_keys as $v) { $newArr[$v] = $array[$v]; } return $newArr; } |