Jump to content

[SOLVED] Add element, loop to write to file, the added element doesnt give me a line brk


tvance929

Recommended Posts

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

 

 

$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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.