How do I show something, for every 4th entry?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

How do I show something, for every 4th entry?

Post by simonmlewis »

I need to show a vertical line after a DIV, for every four entry.
I did do it like this:

Code: Select all

      if ($count == 4 || $count == 8 || $count == 12 || $count == 16 || $count == 20 || $count == 24 || $count == 28 || $count == 32 || $count == 36 || $count == 40 || $count == 44 || $count == 48 || $count == 52 || $count == 56) { }
But now there will be a random set up to an unforeseen figure.

I've since tried this:

Code: Select all

      $count ++;
if (!{$count} % 4) {}
But it errors saying
unexpected '{'
So how do I do it? I assume the latter means is asking if $count is dividable by 4.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: How do I show something, for every 4th entry?

Post by simonmlewis »

Love it when I solve my own issue!

Code: Select all

if (($count % 4) == 0)
{}
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
Post Reply