You can "change" the key of an array element simply by setting the new key and removing the old:
$array[$newKey] = $array[$oldKey];
unset($array[$oldKey]);
But this will move the key to the end of the array.
Is there some elegant way to change the key without changing the order?
(PS: This question is just out of conceptual interest, not because I need it anywhere.)
$arr[$oldKey]if this works as an argument to a function which removes$oldKeyfrom$arr? I think PHP might be more interesting than I previously thought, will have to look into this …$array[$oldKey]will just return the value with the key$oldKey.unset()delete the element from the array? How does PHP even know in which array it should delete the value 5?