note 63580 added to function.array-chunk
| From: | php_at_dhaas | Date: | Fri, 24 Mar 2006 09:46:28 +0000 |
| Subject: | note 63580 added to function.array-chunk | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-106525@lists.php.net to get a copy of this message | ||
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);
----
Server IP: 80.78.242.20
Probable Submitter: 62.46.16.171
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.array-chunk.php
Edit -- http://master.php.net/note/edit/63580
Del: integrated -- http://master.php.net/note/delete/63580/integrated
Del: useless -- http://master.php.net/note/delete/63580/useless
Del: bad code -- http://master.php.net/note/delete/63580/bad+code
Del: spam -- http://master.php.net/note/delete/63580/spam
Del: non-english -- http://master.php.net/note/delete/63580/non-english
Del: in docs -- http://master.php.net/note/delete/63580/in+docs
Del: other reasons-- http://master.php.net/note/delete/63580
Reject -- http://master.php.net/note/reject/63580
Search -- http://master.php.net/manage/user-notes.php