note 80909 added to function.array-splice
| From: | pauljamescampbell at gmail dot com | Date: | Wed, 06 Feb 2008 14:46:36 +0000 |
| Subject: | note 80909 added to function.array-splice | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-135820@lists.php.net to get a copy of this message | ||
Here's my own take on an array slice method that preserves keys from an associative array.
/**
* Array slice function that preserves associative keys
*
* @function associativeArraySlice
*
* @param Array $array Array to slice
* @param Integer $start
* @param Integer $end
*
* @return Array
*/
function associativeArraySlice($array, $start, $end) {
// Method param restrictions
if($start < 0) $start = 0;
if($end > count($array)) $end = count($array);
// Process vars
$new = Array();
$i = 0;
// Loop
foreach($array as $key => $value) {
if($i >= $start && $i < $end) {
$new[$key] = $value;
}
$i++;
}
return($new);
}
----
Server IP: 194.145.210.3
Probable Submitter: 217.150.120.130
----
Manual Page -- http://www.php.net/manual/en/function.array-splice.php
Edit -- https://master.php.net/note/edit/80909
Del: integrated -- https://master.php.net/note/delete/80909/integrated
Del: useless -- https://master.php.net/note/delete/80909/useless
Del: bad code -- https://master.php.net/note/delete/80909/bad+code
Del: spam -- https://master.php.net/note/delete/80909/spam
Del: non-english -- https://master.php.net/note/delete/80909/non-english
Del: in docs -- https://master.php.net/note/delete/80909/in+docs
Del: other reasons-- https://master.php.net/note/delete/80909
Reject -- https://master.php.net/note/reject/80909
Search -- https://master.php.net/manage/user-notes.php