![]() |
PHP Question
Soul...you out there...this is an easy one I think...I just hate loops...
I would like to print a line...after every 5 lines... Example: how's life... how's life... how's life... how's life... how's life... JUST FINE THANKS... how's life... etc... thanks in advance |
Keep a counter of how many lines you've printed and every time you print a line check the mod result of the counter.
if ($counter%5=0) { echo "This is the line to print every 5th line." } Basically if the reminder of the counter divided by 5 is 0 you want to print that line. I typed it wrong before and this probably wrong, too, but that's the general concept anyways. [This message has been edited by FATPad (edited 01-13-2002).] |
Holy fucken christ am I an idiot now. I shouldn't be near a keyboard.
[This message has been edited by FATPad (edited 01-13-2002).] |
for ($i=1; $i<20; $i++)
{ echo "some text $i \n "; if (!($i % 5)) { echo "line 5"; } } NOTE u have to start with an 1 not 0 ... ------------------ ah you have been blessed with 72 virgins? |
works http://bbs.gofuckyourself.net/board/smile.gif
awechen@office -- /home/awechen > ./php -q ? for ($i=1; $i<20; $i++) { echo "some text $i \n "; if (!($i % 5)) { echo "line 5\n"; } }? some text 1 some text 2 some text 3 some text 4 some text 5 line 5 some text 6 some text 7 some text 8 some text 9 some text 10 line 5 some text 11 some text 12 some text 13 some text 14 some text 15 line 5 some text 16 some text 17 some text 18 some text 19 awechen@office -- /home/awechen > ------------------ ah you have been blessed with 72 virgins? [This message has been edited by awechen (edited 01-14-2002).] |
| All times are GMT -7. The time now is 06:36 PM. |
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2026, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123