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
What an image next to your comments?
visit gravatar.com
Message:
want a website, do ya?

latest projects

Image frame
RG Active
view site- RG Active
Image frame
Property Investment Project
view site- Property Investment Project

latest scribbles

latest comments

zurin Gravatar frame
zurin said
hi, i’m having problem with this function. it works fine...
Karlos Gravatar frame
Karlos said
Awesome awesome awesome :) Just started re-designing...
satheesh Gravatar frame
satheesh said
It solved my problem. Thank you. Is it possible to get the...

blog categories

Get a free quote