note 100496 modified in function.array-slice by danbrown
| From: | danbrown@php.net | Date: | Wed, 20 Oct 2010 01:22:15 +0000 |
| Subject: | note 100496 modified in function.array-slice by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-173291@lists.php.net to get a copy of this message | ||
An implementation of array_slice that do not resets the cursor.
<?php
function get_from_array($arr, $start, $length)
{
$sliced = array();
foreach ($arr as $k => $v)
{
if ($start <= $k && $k <= $start + $length - 1)
{
$sliced[] = $v;
if (count($sliced) == $length) break;
}
}
return $sliced;
}
?>
Cheers,
Joel A. Villarreal Bertoldi
--was--
An implementation of array_slice that do not resets the cursor.
function get_from_array($arr, $start, $length)
{
$sliced = array();
foreach ($arr as $k => $v)
{
if ($start <= $k && $k <= $start + $length - 1)
{
$sliced[] = $v;
if (count($sliced) == $length) break;
}
}
return $sliced;
}
Cheers,
Joel A. Villarreal Bertoldi
CordobaSitios.com | Web Solutions
JoelAlejandro.com | Multidesign Studio
http://php.net/manual/en/function.array-slice.php