//生成下标数组 $numbers = range (0,$ccc); //shuffle 将数组顺序随即打乱 shuffle ($numbers); //array_slice 取该数组中的某一段 $result = array_slice($numbers,0,$params['select_num']); foreach ($result as $r){ $ary[] = $ids[$r]; }