【发布时间】:2014-04-14 15:37:06
【问题描述】:
下面的代码从 txt 文件中选择(不重复)随机行。
$filename = "randomlines.txt";
$how_many_to_show = 10;
if ($random = file($filename)) {
shuffle($random);
for ($i = 0; $i < $how_many_to_show; $i++) {
$color[$i]=$random[$i];
}
} else {
die('Could not get contents of: ' . $filename);
}
它工作正常。当我输入以下字符串时
print($fileContents[$i]. '<br />');
代替这个
$color=$random[$i];
我在我的屏幕上看到 10 条不同的线,从 randomlines.txt 中提取
但是,我需要将每个不同的随机行与 10 个不同的变量(例如 $color1、$color2....$color10)关联起来,以供后续代码使用。
【问题讨论】:
-
你的解释很难理解。
-
我尝试以不同的方式编写文本。那样可以么?对不起我的英语不好:)