Web Design Blog

This is where we store some of our Web Development thoughts, tips and tricks, just because we like to share.

PHP- Check If A Number Is Multiple Of Another Number

This is one of those posts that is purely a reminder for myself. It’s something so simple, but for some reason or another, I tend to forget.

Suppose I have a loop, and I want to call a certain action on every 5th loop. For example, on the 5th, 10th, 15th..etc count, I want to call an action.

1
2
3
4
5
6
7
8
9
<?
for($i = 1; $i < 21; $i++)
{
	if ($i % 5 == 0)
	{
		echo "Hello World";
	}
}
?>

In the example above, “Hello World” will echo on the 5th, 10th, 15th and 20th count.

13 Sep 2009 / 0 Comments / PHP Scripts, Tips & Tricks / by Maruf

Leave a Reply

© 2012 BrightCherry :)