note 102553 deleted from function.array-chunk by danbrown

From: Date: Mon, 21 Feb 2011 13:51:42 +0000
Subject: note 102553 deleted from function.array-chunk by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-177176@lists.php.net to get a copy of this message
Note Submitter: ismailbaskin1 at gmail dot com ---- <?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 ) ) */ ?>

« previous php.notes (#177176) next »