PHP array_chunk() functionThe array_chunk() function is built-in function in PHP. The array_chunk function splits an array into chunks of new arrays. This function divides an array into different block of new arrays. Syntax
Important Note: The last chunk may contain less elements than the desired size of the chunk.Example 1Output: Array ( [0] => Array ( [0] => DOG [1] => CAT) [1] => Array ( [0] => LION [1] => ELEPHANT ) [2] => Array ( [0] => MONKEY [1] => TIGER ) ) Example 2Output: Array ( [0]=> Array ( [0]=> a [1]=> b ) [1]=> Array ( [2]=> c [3]=> d ) [2]=> Array ( [4]=> e ) ) Example 3Output: Array ( [0] => Array ( [0] => ajay [1] => sonoo [2] => rahul [3] => sid ) [1] => Array ( [0] => raj ) ) Array ( [0] => Array ( [0] => ajay [1] => sonoo ) [1] => Array ( [2]=>rahul [3] => sid ) [2] => Array ( [4] => raj ) ) Example 4Output: Array ( [0] => Array ( [a] => Adobe [b] => Bosch ) [1] => Array ( [c] => Cummins [d] => Dlf ) )
Next TopicPHP Array Functions
|