2013-07-01 2 views
0

배열 변수 값 내에있는 변수 값을 업데이트하려고합니다.PHP에서 배열 변수 값 내의 변수 값을 변경하십시오.

나는 파일을 쓰고있는 것을 볼 것이다 : file_put_contents(). implode("\r\n", $contents)...에는 $contents 변수가 들어 있습니다.

나는 그것은 $ 내용 배열이 경우 $body_file_count에서 변수 값을 업데이트 할 수 없습니다 꽤 분명 년대 if ($i == $per_file) {...

의 모든 반복을 증가시킬 $body_file_count이 필요합니다.

$body_file_count은 출력되는 파일 수입니다. 실제로 파일 제목에서 같은 수의 : $file_count ...

기본적으로, 난 그냥에 $body_file_count를 작성해야합니다 : 각각의 경우 ($i == $per_file) { 반복에

$default_contents=$contents=array("BODY CONTENT TOP . "$body_file_count" . "); 

. 분명히 $body_file_count을 스크랩하면 $ file_count를 $content에 전달할 수 있습니다. $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() 

답변

1

먼저 당신이 $의 default_contents에 문자열 연결 연산자 (".")를 추가하는 것을 잊지 내가 당신의 질문을 이해있는 경우 나도 몰라

을 initialitation 것을 조심. 제공하는 외에 다른 작업을 위해이 변수가 필요하지 않은 경우 내가 당신의 문제를 이해하는 경우 업데이트를 시도 할 수 있습니다하여 $는 또한


$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; 
     $file_count++; 
     $body_file_count++; 
     $default_contents = array("BODY CONTENT TOP . " . $body_file_count . " . "); 
     $contents = $default_contents; 
    } // End of if() 
} // End of while() 

$ body_file_count을 ++ 변경 매번 default_contents 초기 내용은 그냥 멀리 걸릴 수 있습니다


$body_file_count = 0; 
$footer = "FOOTER"; 
$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; 
     $file_count++; 
     $body_file_count++; 
     $contents = array("BODY CONTENT TOP . " . $body_file_count . " . "); 
    } // End of if() 
} // End of while() 

+0

나는 이것을 이미 시도한 것으로 생각했지만 if 반복의 끝에 $ 내용을 두지 않았다. 지금 $ file_count OK를 출력하고있는 것으로 보입니다. 제안 해 주셔서 감사합니다. – OldWest