I am trying to update a variable value that is within an array variable value.
You will see I am writing out a file with: file_put_contents(). The implode("\r\n", $contents)... contains the $contents variable.
I need $body_file_count to increment every iteration of the if ($i == $per_file) {...
It's pretty evident the $contents array cannot update a variable value in this case $body_file_count.
$body_file_count is the number of files outputted. It's actually the same number in the file title: $file_count...
Basically, I just need to write the $body_file_count to the:
$default_contents=$contents=array("BODY CONTENT TOP . "$body_file_count" . ");
on each if ($i == $per_file) { iteration. Obviously I could scrap $body_file_count if I could pass $file_count to the $content as $file_count is updating the title as expected.
$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()