The array_chunk() function used for split an array into chunks.
Syntax
array_chunk(array,size,preserve_keys);
size-The size of each chunk
preserve_keys-true -Keys will be preserved
false - Default. Reindex the chunk numerically
Example
$names=array("Ram","Shyam","Ghanshyam","Ravi","Anil","Ramshahay");
print_r(array_chunk($names,2));
Output
Array (
[0] => Array ( [0] => Ram [1] => Shyam )
[1] => Array ( [0] => Ghanshyam [1] => Ravi )
[2] => Array ( [0] => Anil [1] => Ramshahay )
)
Copyright ©2022 coderraj.com. All Rights Reserved.