tvance929 Posted March 4, 2009 Share Posted March 4, 2009 Say I add Pvt Bird to the my Array and then try and do the for each I get this in my text file: PFC_bird,634LT._to66ad,33354 CPT_twwwerad,6334 fred, 5454 GENE, 5454 todd, 4343 COL_trerad,3334 SGT_toad,3334 joe, 2343 mike, 33 All the other scores give me the nice line break but the one I added to the array does not... here is more of my code to show you more what Im doing: if ($arrayCount < 10) { //Add new name and score to end $scoresArray[$finalName] = $score; } elseif ($score > end($scoresArray)) { array_pop($scoresArray); $scoresArray[$finalName] = $score; } //Reverse order $result = array_reverse($scoresArray, true); $File = "aa.txt"; $Handle = fopen($File, 'w+'); while(list($Name, $Score)=each($result)) { $newScore = $Name.",".$Score; fwrite($Handle, $newScore); //echo $Name."--".$Score."<br/>"; } fclose($Handle); --------------------------------- Again this all works great except for the one new score that I added to the array -- it prints out but does not give me a new line in my text file......???? *** BTW - I have a confusing convoluted post that I started last night that eventually gets to this point... I wanted to delete that one and add this one. But I cannot figure out how to delete my other post. Thanks so much! t Link to comment https://forums.phpfreaks.com/topic/147934-solved-add-element-loop-to-write-to-file-the-added-element-doesnt-give-me-a-line-brk/ Share on other sites More sharing options...
premiso Posted March 4, 2009 Share Posted March 4, 2009 $score = $score . "\n"; if ($arrayCount < 10) { //Add new name and score to end $scoresArray[$finalName] = $score; } elseif ($score > end($scoresArray)) { array_pop($scoresArray); $scoresArray[$finalName] = $score; } Should solve the issue. Link to comment https://forums.phpfreaks.com/topic/147934-solved-add-element-loop-to-write-to-file-the-added-element-doesnt-give-me-a-line-brk/#findComment-776493 Share on other sites More sharing options...
tvance929 Posted March 4, 2009 Author Share Posted March 4, 2009 thanks!!!! Link to comment https://forums.phpfreaks.com/topic/147934-solved-add-element-loop-to-write-to-file-the-added-element-doesnt-give-me-a-line-brk/#findComment-776664 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.