php - split array into parts with array_chunk function

php
voted: 0
vote
php array chunks

second parameter defines a size of the chunked subarrays. third parameter defines if originale keys should be preserved in chunked arrays. array chunk returns array with chunked subarrays

<?php
$codes = array(
	'aBc' => 'abc',
	'aBC' => 'aabC',
	'aBCd' => 'abc',
	'bCd' => 'bcd',
	'bcde' => 'bcd'
	);
	print_r(array_chunk($codes, 2, false));
	print_r(array_chunk($codes, 2, true));
?>

output
Array
(
    [0] => Array
        (
            [0] => abc
            [1] => aabC
        )

    [1] => Array
        (
            [0] => abc
            [1] => bcd
        )

    [2] => Array
        (
            [0] => bcd
        )

)
Array
(
    [0] => Array
        (
            [aBc] => abc
            [aBC] => aabC
        )

    [1] => Array
        (
            [aBCd] => abc
            [bCd] => bcd
        )

    [2] => Array
        (
            [bcde] => bcd
        )

)
working url: not entered
version: not entered
Leave a Comment:
Characters left:
No comments yet.