LemonInflux Posted May 4, 2008 Share Posted May 4, 2008 Here is my array: <?php array('testKey' => 'testValue', 'secondTestKey' => 'secondTestValue', 'thirdTestKey' => 'thirdTestValue'); ?> How do I, for example, edit the key (not value) 'testKey', to 'testEditKey'? Thanks in advance, Tom Link to comment https://forums.phpfreaks.com/topic/104080-edit-array-key/ Share on other sites More sharing options...
DarkWater Posted May 4, 2008 Share Posted May 4, 2008 Uhh, not sure if there's an easier way to do it, but this would work: $keys = array_keys($testarray); $values = array_values($testarray); $keys[0] = "testEditkey"; $newarray = array_combine($keys, $values); >_> Probably an easier way to do it, but I just can't think of it. Link to comment https://forums.phpfreaks.com/topic/104080-edit-array-key/#findComment-532812 Share on other sites More sharing options...
p2grace Posted May 4, 2008 Share Posted May 4, 2008 hmm not sure if there's a built-in function for that. If there isn't you could do something like this: <?php $val = $arr['testKey']; unset($arr['testKey']); $arr['testEditKey'] = $val; ?> Link to comment https://forums.phpfreaks.com/topic/104080-edit-array-key/#findComment-532813 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.