note 34922 added to function.array-slice
| From: | bishop at rack1 dot php dot net | Date: | Tue, 12 Aug 2003 07:23:44 +0000 |
| Subject: | note 34922 added to function.array-slice | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-53935@lists.php.net to get a copy of this message | ||
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;
}
----
Manual Page -- http://www.php.net/manual/en/function.array-slice.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+34922
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+34922&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+34922&report=yes