The built-in function array_chunk() splits an array into chunks. This function accepts 2 parameters. The first one would be the array, and the second one would be the amount. This function returns a new multidimensional array.
<?php
// Fill array
$arr = array('PHP', 'HTML', 'CSS', 'XHTML', 'SGML', 'JSP');
// Chunk into X pieces
$chuncked = array_chunk($arr, 2);
// Show the result
echo '<pre>'. print_r($chuncked, true) .'</pre>';
?>
The above example would result in:
Array
(
[0] => Array
(
[0] => PHP
[1] => HTML
)
[1] => Array
(
[0] => CSS
[1] => XHTML
)
[2] => Array
(
[0] => SGML
[1] => JSP
)
)
Mail this!
- Comments (0)
- PingBacks (0)
- TrackBacks (0)


» Latest comments