Jump to content

How would i do this??


Orionsbelter

Recommended Posts

How would i do this? say for example i execute a while loop that will loop for 30 times, however each third i want it echo Hello; so this means at loop 3, 6, 9, 12, 15 etc it will echo Hello.

 

Also so i had a table that consisted of 3 cols, the same again the loop goes for 30 times but this time it creates a new row and each third loop for example 3, 6, 9, 12, 15 etc it created another row.

 

For example the PHP interpreter would say ok loop this until 30 then it'll go 1 2 3 NEW ROW 4 5 6 NEW ROW 7 8 9 NEW ROW etc.

 

How are these done?

 

Thank you for reading

Link to comment
https://forums.phpfreaks.com/topic/196806-how-would-i-do-this/
Share on other sites

Modulus is your friend.  It's the remainder of a division. 

 

Here's an example.

 

$arr = array();
for($i=0; $i<100; $i++)
{
if(($i%3) == 0)//If the division by 3 has 0 for remainder, do the following.
{
	echo $i . " <-- Hi<BR>";	
}
else//Otherwise, do this.
{
	echo $i . "<BR>";		
}
}

Link to comment
https://forums.phpfreaks.com/topic/196806-how-would-i-do-this/#findComment-1033118
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.