【发布时间】:2013-06-28 06:13:16
【问题描述】:
我正在尝试更新数组变量值中的变量值。
你会看到我正在写出一个文件:file_put_contents()。 implode("\r\n", $contents)... 包含 $contents 变量。
我需要$body_file_count 来增加if ($i == $per_file) {... 的每次迭代
很明显 $contents 数组在这种情况下无法更新变量值$body_file_count。
$body_file_count 是输出的文件数。文件标题中其实是同一个数字:$file_count...
基本上,我只需要将$body_file_count 写到:
$default_contents=$contents=array("BODY CONTENT TOP . "$body_file_count" . ");
每个 if ($i == $per_file) { 迭代。显然,如果我可以将 $file_count 传递给$content,我可以废弃$body_file_count,因为$file_count 正在按预期更新标题。
$body_file_count = 0;
$footer = "FOOTER";
$default_contents = $contents = array("BODY CONTENT TOP . "$body_file_count" . ");
while ($row = mysql_fetch_array($result)) {
$line = "...";
$contents[] = $line; // Each array element will be a line in the text file
$i++;
$recs++;
if ($i == $per_file) {
$contents[] = $footer; // Add the footer to the end
file_put_contents($_POST["a"] . "-#" . $file_count . "-" . date('Y') . "-" . $_POST["b"] . "-" . $recs . "-" . $txtdate . '.txt', implode("\r\n", $contents));
$i = 0;
$recs = 0;
$contents = $default_contents;
$file_count++;
$body_file_count++;
} // End of if()
} // End of while()
【问题讨论】:
标签: php arrays if-statement while-loop