4

I have an array with 3200 values. A user chooses a number (let's say 50). I want to divide the big array into smaller arrays, each of them containing 50 values (the last one containing the remainder).

How would you do that?

2
  • why do you want to split it in smaller chunks? Commented Jan 21, 2011 at 15:36
  • 1
    Don't forget that php.net is a great resource for determining what built-in functions PHP has. ca.php.net/manual/en/ref.array.php Commented Jan 21, 2011 at 15:40

3 Answers 3

9

array_chunk

e.g.

 $arrays = array_chunk($my_big_array, 50);
Sign up to request clarification or add additional context in comments.

Comments

5
array array_chunk ( array $input , int $size [, bool $preserve_keys = false ] )

Check this: http://php.net/manual/en/function.array-chunk.php

Comments

3

Depending on how you want to do it array_chunk() might be a good place to start.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.