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

  • Home
  • SEARCH
  • 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 6796051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:25:14+00:00 2026-05-26T18:25:14+00:00

I am going nuts here – hope you can help me figure this out!

  • 0

I am going nuts here – hope you can help me figure this out! What is supposed to be very simple math is utterly confusing me.

$columns = 3;
$items = range(1,20);
$total = count($items);

$col1 = ???; $col2 = ???; $col3 = ???;

// $col1 must be an array of (1,2,3,4...)
// $col2 must be an array of (8,9,10,11...)
// $col3 must be an array of (15,16,17,18...)

COL1       COL2        COL3
1          8           15
2          9           16
3          10          17
4          11          18
5          12          19
6          13          20
7          14

The above is a visual example of what I am trying to achieve. Basically, for any given number of items in an array and for any given number of columns, how do I produce n number of arrays (equalling number of columns) that are as equal length as possible. If equal length is not possible (as in the example above), they must be spread out as evenly as possible and the last array must be the shortest.

Any guidance on how I construct $col1/2/3 in the example above would be much appreciated!

Please ignore the fact that I used range and integers to generate the array – this is just to simplify the example. Assume the array will contain strings.

Thanks for any help!

  • 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-05-26T18:25:14+00:00Added an answer on May 26, 2026 at 6:25 pm

    You do want to use array_chunk, but you need to calculate the chunk size yourself:

    list($col1, $col2, $col3) = array_chunk($items, ceil($total / $columns));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is driving me nuts so I hope someone can help an Objective-C noob
I am going nuts trying to figure out this all day but without success.
I'm going a little nuts trying to figure out how to use template inheritance
please help! I'm really going nuts with this problem! I have a CGI perl
I'm going nuts here. For some reason I can't find a single, complete example
i'm going nuts here with this and i have a deadline. So i have
Going nuts over here... From within the shell, I can do: product.tags.add(a_new_tag) The tag
I'm going nuts on this. (as most people posting here lol) I have a
This is driving me nuts. I can't work it out stepping through with Firebug
I'm going nuts here, trying to get my system configured. I have a laptop

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.