Home >Backend Development >PHP Tutorial >随机读取TXT内容的有关问题!

随机读取TXT内容的有关问题!

WBOY
WBOYOriginal
2016-06-13 11:13:171061browse

随机读取TXT内容的问题!!
$file=file('webyuan.txt');
$file2=file('lk.txt');
$max=count($file)-1;
$max2=count($file2)-1;
for($i=0;$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  $index=mt_rand(0,$max);
  $index2=mt_rand(0,$max2);
$temp = trim($file["$index"]);
$temp2 .= trim($file2["$index2"]);
}
echo $temp2;
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn