note 38668 added to function.array-chunk
| From: | gphemsley at users dot sourceforge dot net | Date: | Fri, 02 Jan 2004 06:25:29 +0000 |
| Subject: | note 38668 added to function.array-chunk | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-62769@lists.php.net to get a copy of this message | ||
For those of you that need array_chunk() for PHP < 4.2.0, this function should do the trick:
<?php
function array_chunk( $input, $size, $preserve_keys = FALSE )
{
@reset( $input );
$i = $j = 0;
while( @list( , $value ) = @each( $input ) )
{
if( !( isset( $chunks[$i] ) ) )
{
$chunks[$i] = array();
}
if( count( $chunks[$i] ) < $size )
{
if( $preserve_keys )
{
$chunks[$i][$j] = $value;
$j++;
}
else
{
$chunks[$i][] = $value;
}
}
else
{
$i++;
if( $preserve_keys )
{
$chunks[$i][$j] = $value;
$j++;
}
else
{
$j = 0;
$chunks[$i][$j] = $value;
}
}
}
return $chunks;
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.array-chunk.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+38668
Delete -- http://master.php.net/manage/user-notes.php?action=delete+38668&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+38668&report=yes
Search -- http://master.php.net/manage/user-notes.php