NYCPHP Meetup

NYPHP.org

[nycphp-talk] Rename an array key?

David Krings ramons at gmx.net
Tue Jul 24 12:21:45 EDT 2007


csnyder wrote:
>> What you can do is first identify the key/value pair you want to change.
>> Then read out the value, then use unset($array['key']), then add the
>> saved value to the array with the desired key name.
> 
> The trick is that your new key=>value pair will be at the end of the
> array, not the third element.
> 
> I need to rename a single key "in-place" in a very large array.

Then use Ben's proposal...way cleverer than mine and it gets you what 
you want. I really don't understand why position within the array 
matters. That is why the values have a key, isn't it?

David



More information about the talk mailing list