Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.