note 102553 added to function.array-chunk

[email protected] Mon, 21 Feb 2011 02:56:35 -0800
Newsgroups php.notes
Message-ID <[email protected]>
<?php
function array_chunk_vertical($data, $columns) {
	$newarray = array();
	$i = 0;
	foreach($data as $index => $row){
		$newarray[$i%$columns][$index] = $row;
		$i++;
	}

        return $newarray ;
}

$fruits = array('apple'=>50,'banana'=>35, 'grape' => 85,'pear'=>45,'apricot'=>28,'peach'=>65);

print_r(array_chunk($fruits,2,true));

/*
Classic chunk function
Array
(
    [0] => Array
        (
            [apple] => 50
            [banana] => 35
        )
 
    [1] => Array
        (
            [grape] => 85
            [pear] => 45
        )
 
    [2] => Array
        (
            [apricot] => 28
            [peach] => 65
        )
 
)
*/

echo "\n\n";

print_r(array_chunk_vertical($fruits,2));

/*

vertical chunk function

Array
(
    [0] => Array
        (
            [apple] => 50
            [grape] => 85
            [apricot] => 28
        )
 
    [1] => Array
        (
            [banana] => 35
            [pear] => 45
            [peach] => 65
        )
 
)

*/
?>
----
Server IP: 69.147.83.197
Probable Submitter: 85.105.122.164
----
Manual Page -- http://www.php.net/manual/en/function.array-chunk.php
Edit        -- https://master.php.net/note/edit/102553
Del: integrated  -- https://master.php.net/note/delete/102553/integrated
Del: useless     -- https://master.php.net/note/delete/102553/useless
Del: bad code    -- https://master.php.net/note/delete/102553/bad+code
Del: spam        -- https://master.php.net/note/delete/102553/spam
Del: non-english -- https://master.php.net/note/delete/102553/non-english
Del: in docs     -- https://master.php.net/note/delete/102553/in+docs
Del: other reasons-- https://master.php.net/note/delete/102553
Reject      -- https://master.php.net/note/reject/102553
Search      -- https://master.php.net/manage/user-notes.php