..
Array_chunk function divides an array of new shares thus creating arrays.
The function accepts three parameters in question:
$ A = array ("a" => "Cat", "b" => "Dog", "c" => "Mouse", "d" => "Cow");
print_r (array_chunk ($ a, 2));
The output of the code above will be:
Array (
[0] => Array (
[0] => Cat
[1] => Dog
)
[1] => Array (
[0] => Rat
[1] => Cow
)
)
We see a second example in which we will preserve the original keys arry:
$ A = array ("a" => "Cat", "b" => "Dog", "c" => "Mouse", "d" => "Cow");
print_r (array_chunk ($ a, 2, true));
The output of the code above will be:
Array (
[0] => Array (
[A] => Cat
[B] => Dog
)
[1] => Array (
[C] => Rat
[D] => Cow
)
)
| |
Linux (Course)
Complete guide to open-source system. From 49 €. |
| |
MySQL (Course)
Management of open-source database. From 39 €. |
| |
PHP (Course)
Full course for creating dynamic Web sites. From 49 €. |