//$begin最小数,$end最大数,$limit截取数量,$field插入字段
function getRandNum($begin,$end,$limit,$field)
{
$rand_array=range($begin,$end);
//注释:rang()创建一个包含从_ 到_ 之间的元素范围的数组:
//示例:range(0,5);Array ( [0] => 0 [1] => 1 [2] => 2 [3] => 3 [4] => 4 [5] => 5 )
shuffle($rand_array);//打乱排列
$rand_array=array_slice($rand_array,0,$limit);
//注释:从$rand_array一维数组中,从第一个元素开始,截取$limit个。
//示例:array_slice(array,start,length),Array ( [0] => 0 [1] => 1 [2] => 2 [3] => 3 [4] => 4 [5] => 5 )
foreach($rand_array as $key=>$val)
{ $array[][$field]=$val;
//注释:addAll(二维数组)
//示例:Array ( [0] => Array ( [id] => 15805 ) [1] => Array ( [id] => 85580 )。。。
}
return $array;
}
$tem_arr = getRandNum(0,99999,100,'id');
echo '<pre>';
print_r($tem_arr);