PHP- Call Action In A Loop On A Set Multiple Value

Image frame
PHP- Call Action In A Loop On A Set Multiple Value
Maruf
Sep 13th, 2009
Maruf scribbled this post.

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.


Filed away: PHP

feel free to leave a scribble

Name:
Email:
gravatar
Want an image next to your comments?
visit gravatar.com
Message:
Get a free quote