[Editors note: This function was based on a previous function by gphemsley at nospam users dot sourceforge.net]
For those of you that need array_chunk() for PHP < 4.2.0, this function should do the trick:
<?php
if (!function_exists('array_chunk')) {
function array_chunk( $input, $size, $preserve_keys = false) {
@reset( $input );
$i = $j = 0;
while( @list( $key, $value ) = @each( $input ) ) {
if( !( isset( $chunks[$i] ) ) ) {
$chunks[$i] = array();
}
if( count( $chunks[$i] ) < $size ) {
if( $preserve_keys ) {
$chunks[$i][$key] = $value;
$j++;
} else {
$chunks[$i][] = $value;
}
} else {
$i++;
if( $preserve_keys ) {
$chunks[$i][$key] = $value;
$j++;
} else {
$j = 0;
$chunks[$i][$j] = $value;
}
}
}
return $chunks;
}
}
?>