array_chunk()
Similar to str_split() for strings, this function splits up an array into a multidimensional array.
The result is a multidimensional array with each element containing a number of elements of your original array. By default, the original keys will be lost. Set the third parameter to true and the keys will be preserved.
$arr = array( 'z' => 'apple', 'y' => 'banana', 'x' => 'carrot', 'w' => 'durian', 'v' => 'eggplant', 'u' => 'fennel', 't' => 'grapefruit', 's' => 'honeydew', 'r' => 'iceburg lettuce', 'q' => 'jackfruit', 'p' => 'kale' ); $new1 = array_chunk( $arr, 2 ); /* array ( 0 => array ( 0 => 'apple', 1 => 'banana', ), 1 => array ( 0 => 'carrot', 1 => 'durian', ), 2 => array ( 0 => 'eggplant', 1 => 'fennel', ), 3 => array ( 0 => 'grapefruit', 1 => 'honeydew', ), 4 => array ( 0 => 'iceburg lettuce', 1 => 'jackfruit', ), 5 => array ( 0 => 'kale', ) ) */ $new2 = array_chunk( $arr, 2, true ); /* array ( 0 => array ( 'z' => 'apple', 'y' => 'banana', ), 1 => array ( 'x' => 'carrot', 'w' => 'durian', ), 2 => array ( 'v' => 'eggplant', 'u' => 'fennel', ), 3 => array ( 't' => 'grapefruit', 's' => 'honeydew', ), 4 => array ( 'r' => 'iceburg lettuce', 'q' => 'jackfruit', ), 5 => array ( 'p' => 'kale', ) ) */
See the manual entry for array_chunk()
