Advertisement
Guest User

Ad every Nth

a guest
Apr 24th, 2013
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. You can use Modulus division to add in every Nth (in this case 6th) instance. So…
  2. if ($i == 6 || $i == 12 || $i == 18)
  3. would be
  4. if ($i % 6 == 0)
  5. One pitfall with this is that 0 % 3 = 0 so with the counter ($i) starting at 0 you could also get an ad at the beginning of the loop. Deans example adds 1 to $i before the first iteration of the loop anyway so that shouldn’t be an issue. But just in case, to stop that you can use.
  6. if ($i > 0 && $i % 6 == 0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement