note 34308 added to function.array-unshift
| From: | chris dot NoThxSpam dot given at hp dot com | Date: | Wed, 23 Jul 2003 17:17:59 +0000 |
| Subject: | note 34308 added to function.array-unshift | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-52504@lists.php.net to get a copy of this message | ||
If you need to change the name of a key without changing its position in the array this function may
be useful.
function array_key_change($Old, $New, $In, $NewVal=NULL) {
$Temp = array();
while(isset($Temp[$Old]) == false) {
list($k, $v) = each($In);
$Temp[$k] = $v;
unset($In[$k]);
}
if($NewVal == NULL) {
$NewVal = $Temp[$Old];
}
unset($Temp[$Old]);
$Temp = array_reverse($Temp);
$In = array_merge(array($New=>$NewVal), $In);
while(list($k,$v) = each($Temp)) {
$In = array_merge(array($k=>$v), $In);
}
return($In);
}
----
Manual Page -- http://www.php.net/manual/en/function.array-unshift.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+34308
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+34308&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+34308&report=yes