note 34922 deleted from function.array-slice by didou
| From: | didou@php.net | Date: | Tue, 12 Aug 2003 07:25:12 +0000 |
| Subject: | note 34922 deleted from function.array-slice by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-53937@lists.php.net to get a copy of this message | ||
Note Submitter: bishop
----
The script at stargeek.com had some issues (not stopping if next() passed the end of the script).
Fixed:
function array_slice_assoc($array, $offset, $limit) {
reset($array);
// skip over the first $offset elements
for ($i = 0; $i < $offset; $i++) {
if (! next($array)) {
return array ();
}
}
// get the slice
$max = $offset + $limit - 1;
for ($i = $offset; $i <= $max; $i++) {
$key = key($array);
$new_array[$key] = current($array);
if (! next($array)) {
break;
}
}
return $new_array;
}