If you were a little crazy, you could write a function.
function changeKey(array $array, $oldKey, $newKey) { if ( ! array_key_exists($array, $oldKey)) { return $array; } $array[$newKey] = $array[$oldKey]; unset($array[$oldKey]); return $array; }
This will do nothing if the source key is missing. It will also overwrite existing keys.
source share