note 63580 deleted from function.array-chunk by bjori
| From: | bjori@php.net | Date: | Fri, 24 Mar 2006 10:04:10 +0000 |
| Subject: | note 63580 deleted from function.array-chunk by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-106528@lists.php.net to get a copy of this message | ||
Note Submitter: php _at_ dhaas [dot] eml (point) cc
Reason: useless
----
Without array_chunk but also splitting up an array:
This function takes a 1-dim array and splits it up in one 2-dim array with alternating content
Like this:
array( 1,2,3,4,5,6,7,8,9 ) gets to
array( [0] => array(1,3,5,7,9), [1] => array(2,4,6,8) )
<?php
function array_zipper($arr)
{
$outarr = array(0=>array(),1=>array());
$linecounter = 0;
foreach( $arr as $value )
{
array_push($outarr[$linecounter++%2],$value);
}
return $outarr;
}
?>
use:
$arr = array(1,2,3,4,5,6,7,8,9);
$outarr = array_zipper($arr);
var_dump($outarr);