Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8407179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:17:50+00:00 2026-06-09T23:17:50+00:00

I am sure I am making this way more complicated than it is… I

  • 0

I am sure I am making this way more complicated than it is…

I have an array of values, lets just say they are numbers for now. I want to display them on a page in 3 columns. So I made 3 loops, one for each column. The first loop I want to loop every 3rd value, starting at index 0. The second loop should start at index 1 and do every third. And the third loop should start at index 2 and loop through every third.

This is what I wrote, which seems to work if you only have 3 things in the array, and I’m sure it’s overly complicated.

Thanks

 <div class="span4 column">
        <?php for ($i = 0; $i <= count($articles_for_board)/3; $i = $i+2):?>
            stuff in here
            </div>
        <?php endfor; ?>
    </div>
    <div class="span4 column">
        <?php for ($i = 1; $i <= (count($all_boards)/3)+1; $i = $i+2):?>
            stuff in here
            </div>
        <?php endfor; ?>
    </div>
    <div class="span4 column">
        <?php for ($i = 2; $i <= (count($all_boards)/3)+2; $i = $i+2):?>
            stuff in here
            </div>
        <?php endfor; ?>
    </div>

So basically, the first column would hold array index 0, 3, 6…
second column would hold 1, 4.. etc
third column would hold 2, 5, 8…

THanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T23:17:51+00:00Added an answer on June 9, 2026 at 11:17 pm

    With a for-loop, you don’t need to worry so much about all that bounds checking. It’s a lot simpler than you think it is:

    for ($i = 0; $i < count($all_boards); $i += 3)
    

    This loop increments by three every iteration — that is, it gets every third member — and it stops as soon as it exceeds the length of $all_boards.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is making me nuts and I'm sure the answer is SO easy. I
I have a RESTful WCF service that has an upload method accepting more than
Sorry, I'm sure making a silly mistake, but did not work out. I'm compiling
I was making sure I knew how to do the op= and copy constructor
Im having trouble making sure my active graphic is positioned outside of the button,
The following is some code for making sure people can't submit if the value
I pushed my app to heroku after making sure it works fine in my
I'm going through some old C#.NET code in an ASP.NET application making sure that
I'm going through some old C#.NET code in an ASP.NET application making sure that
I start GVIM in not-maximized window mode and split its window horizontally making sure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.