On 7/24/07, David Krings <[EMAIL PROTECTED]> wrote:
csnyder wrote: > Anyone know of an easy way to rename an associative array key in place? > > array( 'vegetable'=>'lettuce', 'fruit'=>'coconut', 'bean'=>'chickpea', > 'grain'=>'corn' ) > > I want the third element to be 'legume'=>'chickpea', but it seems to > involve rebuilding the array...? > 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. _______________________________________________ New York PHP Community Talk Mailing List http://lists.nyphp.org/mailman/listinfo/talk NYPHPCon 2006 Presentations Online http://www.nyphpcon.com Show Your Participation in New York PHP http://www.nyphp.org/show_participation.php
