note 24206 added to function.array-shift
| From: | nicolas dot guennoc at devoteam dot com | Date: | Fri, 09 Aug 2002 12:29:38 +0000 |
| Subject: | note 24206 added to function.array-shift | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-34604@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'];
}
--
http://www.php.net/manual/en/function.array-shift.php
http://master.php.net/manage/user-notes.php?action=edit+24206
http://master.php.net/manage/user-notes.php?action=delete+24206
http://master.php.net/manage/user-notes.php?action=reject+24206