Jump to content

[SOLVED] setting comma


tyra

Recommended Posts

Maybe I'm confused but, by judging on what you're asking you're a couple things wrong...

 

1) If you want every fourth number why are you using modulus 2?

 

2) Why do you write to 2 files?

 

3) This should put a comma between every fourth number, from 1 to 100.

 

$filea = fopen('filea.txt', 'wb');

for($i=1; $i{
   if(($i % 4) == 0)
      fwrite($filea, $i . ', ');
   else
      fwrite($filea, $i. ' ');
}
   fclose($filea);
?>

 

If I'm mistaken on what you're trying to accomplish please, give more detail.

Link to comment
https://forums.phpfreaks.com/topic/150435-solved-setting-comma/#findComment-790135
Share on other sites

<?php
$filea = fopen('filea.txt', 'wb');
$fileb = fopen('fileb.txt', 'wb');
$sep = '';
for($i = 1; $i <= 100; $i++)
{
    if($i % 2) fwrite($filea, $i.$sep);
    else {      
           if($i % 8 == 0) $sep = ', '; else $sep = ''; 
           fwrite($fileb, $i. $sep);
    }
}

fclose($filea);
fclose($fileb);
?>

Link to comment
https://forums.phpfreaks.com/topic/150435-solved-setting-comma/#findComment-790170
Share on other sites

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.