note 24206 deleted from function.array-shift by sniper
| From: | sniper@php.net | Date: | Mon, 03 Feb 2003 16:16:29 +0000 |
| Subject: | note 24206 deleted from function.array-shift by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-43334@lists.php.net to get a copy of this message | ||
here is a rewritten array_shift function.
as said above, it keeps the values intact, not like the native array_shift function.
/**
* Rewrite of array_shift
* it keeps the keys intact!
* @param array $array array for the removal of its first element
* @return mixed the removed element
* @access public
**/
function my_array_shift(&$array){
/* move the internal pointer of the array to the first element */
reset($array);
/**
* Read the first element of the array
* return both the vector and hash values
**/
$temp = each($array);
/**
* Remove the element from the array
**/
unset($array[$temp['key']]);
/**
* Return the extracted value as wanted
**/
return $temp['value'];
}