note 34308 modified in function.array-unshift by vrana

From: Date: Tue, 17 Aug 2004 14:52:02 +0000
Subject: note 34308 modified in function.array-unshift by vrana
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-79915@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. <?php 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); } ?> --was-- 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); } http://php.net/manual/en/function.array-unshift.php

« previous php.notes (#79915) next »