The array_chunk() function is used to split an array into several arrays.
Version
(PHP 4 and above)
Syntax
array_chunk(input_array, size, preserve_keys)
Parameters
Name | Description | Required / Optional | Type |
---|---|---|---|
input_array | Specifies the array to split. | Required | Array |
size | The size of each chunk (i.e. the number of elements) | Required | Integer |
preserve_keys | If we set preserve_keys as TRUE, array_chunk function preserves the original array keys. Default is FALSE which will reindex the chunk numerically. | Optional | Boolean |
Return value
A multidimensional numerically indexed array.
Value Type : Array
Pictorial representation of array_chunk() function.
Example -1 : php array_chunk() function.
- <?php
- $input_array = array('name1', 'name2', 'name3', 'name4', 'name5');
- print_r(array_chunk($input_array,2));
- ?>
No comments:
Post a Comment