array array_chunk ( array $arr , int $size [, bool $preserve_keys = false ] )
引數說明:<?php $arr1 = array("C語言中文網", "PHP教學", "http://c.biancheng.net/php/", "Java教學", "http://c.biancheng.net/java/", "Python教學", "http://c.biancheng.net/python/"); print_r( array_chunk($arr1, 3) ); //不保留原有鍵名 print_r( array_chunk($arr1, 3, true) ); //保留原有鍵名 $arr2 = array( 'fruits'=>array('Apple', 'banana', 'pear', 'orange'), 'animal', 'vehicle', 'architecture', 'food'); print_r( array_chunk($arr2, 3) ); print_r( array_chunk($arr2, 3, true) ); ?>執行以上程式的輸出結果如下:
Array
(
[0] => Array
(
[0] => C語言中文網
[1] => PHP教學
[2] => http://c.biancheng.net/php/
)
[1] => Array
(
[0] => Java教學
[1] => http://c.biancheng.net/java/
[2] => Python教學
)
[2] => Array
(
[0] => http://c.biancheng.net/python/
)
)
Array
(
[0] => Array
(
[0] => C語言中文網
[1] => PHP教學
[2] => http://c.biancheng.net/php/
)
[1] => Array
(
[3] => Java教學
[4] => http://c.biancheng.net/java/
[5] => Python教學
)
[2] => Array
(
[6] => http://c.biancheng.net/python/
)
)
Array
(
[0] => Array
(
[0] => Array
(
[0] => Apple
[1] => banana
[2] => pear
[3] => orange
)
[1] => animal
[2] => vehicle
)
[1] => Array
(
[0] => architecture
[1] => food
)
)
Array
(
[0] => Array
(
[fruits] => Array
(
[0] => Apple
[1] => banana
[2] => pear
[3] => orange
)
[0] => animal
[1] => vehicle
)
[1] => Array
(
[2] => architecture
[3] => food
)
)