How to use array_chunk function in PHP?
In this post, We will use array_chunk function splits an array into chunks of new arrays in php.
1. Code:
<?php
function splitArray($array, $lengthNewArray){
$arr = array_chunk($array, $lengthNewArray);
return $arr;
}
$input_array = array('php', 'laravel','java','html');
print_r(splitArray($input_array,2));
?>
2. Example:
Input:
array('php', 'laravel','java','html');
length = 2
Output:
Array ( [0] => Array ( [0] => php [1] => laravel ) [1] => Array ( [0] => java [1] => html ) )