Re: changing a key in an array
| From: | Jason k Larson | Date: | Tue, 21 Jan 2003 14:20:10 +0000 |
| Subject: | Re: changing a key in an array | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-132402@lists.php.net to get a copy of this message | ||
My first question back would be why you create on array with keys you know you want to change, or why in that case it became necessary to dereference the original key.
$a['tmp'] =& $a['t']; // exact same values by reference (no copy)
Only other way I can think of at the moment is to create a copy and unset the original as you described as brute force.
HTH,
Jason k Larson
David T-G wrote:
Hi, all -- If I have an associative array Array ([t] => Array ( [t1] => temp1 [t2] => temp2 ) [f] => Array ( [f1] => foo1 [f2] => foo2 ) )and I want to change the key 't' to, say, 'tmp', is there a way to change it or do I have to use the brute force $a[tmp] = $a[t] ; unset $a[t] ; approach? I expect that, however it's done, it works the same way on just a 1-d assoc array like Array ([t1] => temp1 [t2] => temp2) but in particular I have the 2-d array case that I need to play with today. TIA & HAND :-D