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 8810611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:09:40+00:00 2026-06-14T03:09:40+00:00

Possible Duplicate: php split array into smaller even arrays How can I slice an

  • 0

Possible Duplicate:
php split array into smaller even arrays

How can I slice an array into multiple parts ? Lets say I have this array:

$arr = range(1, 15);

How can I end up with this result :

Array
(
    [0] => Array
        (
            [0] => 1
            [1] => 2
            [2] => 3
        )

    [1] => Array
        (
            [0] => 4
            [1] => 5
            [2] => 6
        )

    [2] => Array
       ............
)

What I’ve tried so far :

$parts = 3;
$slices = array();

for($i=0; $i<($parts * $parts); $i=$i+$parts){
  $sliced = array_slice($arr, $i, (count($arr) / $parts));
  array_push($slices, $sliced);
}

It seems to be working fine only with arrays under 10 elements that makes me confused about why and how that code works really, it doesn’t seem static to me as well.. Is there any other way to do it or a fix for the code?

  • 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-14T03:09:41+00:00Added an answer on June 14, 2026 at 3:09 am

    You can use the built-in function array_chunk instead of writing your own:

    $chunks = array_chunk($arr, 3);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How can I split a comma delimited string into an array in
Possible Duplicate: How can I split a comma delimited string into an array in
Possible Duplicate: PHP, Echoing an array into a string of comma seperated values This
Possible Duplicate: PHP PDO: Can I bind an array to an IN() condition? I
Possible Duplicate: Inserting PHP array into Javascript array I'm reading a file in server
Possible Duplicate: How can I split a list with multiple delimiters? I am a
Possible Duplicate: PHP get all arguments as array? Well, In java I can do
Possible Duplicate: PHP - How to split a paragraph into sentences. I have a
Possible Duplicate: PHP split string into integer element and string I have a directory
Possible Duplicate: Split PDF documents into separate pages using PHP (or possibly perl) How

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.