日期:2014-05-17  浏览次数:20451 次

随机读取TXT内容的问题!!
$file=file('webyuan.txt');
$file2=file('lk.txt');
$max=count($file)-1;
$max2=count($file2)-1;
for($i=0;$i<5;$i++){
  $index=mt_rand(0,$max);
  $index2=mt_rand(0,$max2);
$temp = trim($file["$index"]);
$temp2 = trim($file2["$index2"]);
echo $temp2;
}

这个可以随机输出5个关键词

for{}括号外
输出$temp2就只能得到一个关键词了,
请问如何才能在在括号外也可以随机输出5个关键词

------解决方案--------------------
for($i=0;$i<5;$i++){
  $index=mt_rand(0,$max);
  $index2=mt_rand(0,$max2);
$temp = trim($file["$index"]);
$temp2 .= trim($file2["$index2"]);
}
echo $temp2;