Great question...
I just spent some time to figure it out and came up with a cool way!


check it out!
[EMAIL PROTECTED] fakie]$ cat test.php
<?php
$set = array( 'vegetable'=>'lettuce', 'fruit'=>'coconut', 'bean'=>'chickpea',
      'grain'=>'corn' );
$set = array_flip($set);
$set['chickpea'] = 'legume';
$set = array_flip($set);

/*
$set2 = array_slice($set, -2, 1);
$set2 = array_flip($set2);
$set['chickpea
*/
print_r($set);


So, I flip it, rename the new index and then flip it back to normal. This way lets me edit the index
I normally couldn't edit.

- Ben
Ben Sgro, Chief Engineer
ProjectSkyLine - Defining New Horizons
+1 718.487.9368 (N.Y. Office)

Our company: www.projectskyline.com
Our products: www.project-contact.com

This e-mail is confidential information intended only for the use of the individual to whom it is addressed. ----- Original Message ----- From: "csnyder" <[EMAIL PROTECTED]>
To: "NYPHP Talk" <[email protected]>
Sent: Tuesday, July 24, 2007 11:45 AM
Subject: [nyphp-talk] Rename an array key?


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...?

--
Chris Snyder
http://chxo.com/
_______________________________________________
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

_______________________________________________
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

Reply via email to