note 14645 deleted from function.array-shift by sniper
| From: | sniper@php.net | Date: | Mon, 03 Feb 2003 16:15:50 +0000 |
| Subject: | note 14645 deleted from function.array-shift by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-43331@lists.php.net to get a copy of this message | ||
Here's an array_shift that keeps the keys intact. It's called exactly the same way that
array_shift() is.
function my_array_shift(&$array) {
//and array_shift that keeps the
//keys intact!
reset($array);
$i = 0;
$newArray = array();
while(list($key, $val) = each($array)) {
if ($i > 0) {
$newArray[$key] = $val;
}
else {
$toReturn = $array[$key];
}
$i++;
}
$array = $newArray;
return $toReturn;
} //end my_array_shift