PHP:: How to split a large array in small pieces :: or split array into chunks

Hello All,
Yesterday i was searching for a solution to split large array into small pieces. Suddenly i noticed the that php have a built in function to split array into small pieces. It was very surprise to me ..
Here it is
Function : array array_chunk ( array $input , int $size [, bool $preserve_keys= false ] )

< ?php $input_array = array('a', 'b', 'c', 'd', 'e'); print_r(array_chunk($input_array, 2)); print_r(array_chunk($input_array, 2, true)); ?>

The output will be like this : –

Array
(
[0] => Array
(
[0] => a
[1] => b
)

[1] => Array
(
[0] => c
[1] => d
)

[2] => Array
(
[0] => e
)

)
Array
(
[0] => Array
(
[0] => a
[1] => b
)

[1] => Array
(
[2] => c
[3] => d
)

[2] => Array
(
[4] => e
)

)

Have fun Cheers

About

me : yeay its me arun

Tagged with: , ,
One comment on “PHP:: How to split a large array in small pieces :: or split array into chunks
  1. Technogati says:

    This is a best post like a tutor.
    Thanks for great tip.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.