Grow your CSS skills. Land your dream job.

Detecting increments of 12

  • # May 5, 2010 at 3:17 pm

    Basically what I’d like to do is detect when the index of a loop reaches increments of 12 and then do something else. Right now, my code looks like this:

    Code:
    < ?php
    //Grab thumbnails and display them
    $files = glob("images/gallery/thumb/*.{jpg,gif,png}", GLOB_BRACE);
    for ($i = 00; $i echo <<

  • house

    THUMB;
    if ($i == 11 || $i == 23 || $i == 35 || $i == 47 || $i == 59 || $i == 71 || $i == 83) {
    echo < <

    PANEL;
    }
    }
    ?>

As you can see, it’s this part that needs improving:

Code:
if ($i == 11 || $i == 23 || $i == 35 || $i == 47 || $i == 59 || $i == 71 || $i == 83) {

This code works fine as is, but I’d like for it to not break if the number goes above what is hard coded in.

# May 5, 2010 at 3:47 pm

You want to use the modulus then. However I would start $i at 1 and then knock off 1 when accessing the array to make it easier…If that makes sense

So I think something like

Code:
if ($i % 12 == 0){

}

# May 5, 2010 at 4:38 pm

Wow. That was easy. I’ll have to remember that.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".