Rename array key?

How can I replace in this array [userid] => 14 with [address] => some_address

Can’t find a way to rename a key.

Array ( [userid] => 14 [country_code] => ES [country_name] => España [country_url] => espana [city_name] => Zapateros [city_url] => zapateros [region_name] => Albacete [region_url] => albacete )

You can’t. You remove the old key and add the new key:

unset($array['userid']);
$array['address'] = 'some_address';
1 Like

You can add another key with new elements .

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.