Chunk () function
function
This function splits an array into multiple arrays,
Where the number of cells per array is determined by size
The number of cells in the last array may be few
The resulting array is a cell in a multidimensional array whose index starts at zero
"Scope of Use"
>=4.2.0, PHP5
Use
Array array_chunk (array input, int size [, bool Preserve_keys])
input/Required/segmented array
size/number of units required/split to array
preserve_keys/Optional/true retains the original key name of the array,
False key named zero-based numeric index, default = False
Example
[PHP]
$arr = Array ("Key1" = "Val1", "key2" = "Val2",
"Key3" = "Val3", "Key4" and "Val4");
Print_r (Array_chunk ($arr, 2));
Print_r (Array_chunk ($arr, 2, True));
Print_r (Array_chunk ($arr, 3));
/*
Array
(
[0] = = Array
(
[0] = Val1
[1] = Val2
)
[1] = = Array
(
[0] = Val3
[1] = Val4
)
)
Array
(
[0] = = Array
(
[Key1] = Val1
[Key2] = Val2
)
[1] = = Array
(
[Key3] = Val3
[Key4] = Val4
)
)
Array
(
[0] = = Array
(
[0] = Val1
[1] = Val2
[2] = Val3
)
[1] = = Array
(
[0] = Val4
)
)
*/
Excerpts from Zuodefeng's notes
http://www.bkjia.com/PHPjc/478197.html www.bkjia.com true http://www.bkjia.com/PHPjc/478197.html techarticle Chunk () function "function" This function splits an array into multiple arrays, where the number of cells per array has a size that determines the number of cells in the last array may be a few less ...