Orionsbelter Posted March 28, 2010 Share Posted March 28, 2010 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 Quote Link to comment Share on other sites More sharing options...
zeodragonzord Posted March 28, 2010 Share Posted March 28, 2010 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>"; } } Quote Link to comment Share on other sites More sharing options...
Orionsbelter Posted March 28, 2010 Author Share Posted March 28, 2010 Thank you Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.