Re: [PHP] changing a key in an array

2003-01-23 Thread David T-G
Brent, et al -- ...and then Brent Baisley said... % % I'm not sure how you are creating your array, but your resulting array Well, here's some code with some commentary to perhaps help: - first we define a name for a picture basket; the default is 'default' (we might later get a new

Re: [PHP] changing a key in an array

2003-01-23 Thread Brent Baisley
Unless the user has a lot of baskets, I would assume you would just list all the baskets the user has as links on the web page or as a pop up menu. The value passed by the links or pop up would be the element number of the array item containing the desired basket. To extract a basket by name I

Re: [PHP] changing a key in an array

2003-01-23 Thread Jason k Larson
If you are looking for something as simple as an index or key rename function it can be done and without making any copies of the array or object etc by: $array['new_key_name'] = $array['old_key_name']; unset($array['old_key_name']; The first line creates a reference to the array. The second

Re: [PHP] changing a key in an array

2003-01-23 Thread David T-G
Brent -- ...and then Brent Baisley said... % % Unless the user has a lot of baskets, I would assume you would just list % all the baskets the user has as links on the web page or as a pop up One never knows, but I currently list as many as he has anyway. % menu. The value passed by the

Re: [PHP] changing a key in an array

2003-01-23 Thread David T-G
Jason, et al -- ...and then Jason k Larson said... % % If you are looking for something as simple as an index or key rename Yep. % function it can be done and without making any copies of the array or % object etc by: Cool! % % $array['new_key_name'] = $array['old_key_name']; %

Re: [PHP] changing a key in an array

2003-01-23 Thread David T-G
Jason, et al -- ...and then David T-G said... % % ...and then Jason k Larson said... % % % % If you are looking for something as simple as an index or key rename That was it, indeed, but $t = array(t1 = temp1, t2 = temp2 ) ; $f = array(f1 = foo1, f2 = foo2 ) ; $a['t'] = $t ; $a['f']

Re: [PHP] changing a key in an array

2003-01-23 Thread Chris Boget
So I'm back to the beginning and to funky array wrappers again... I think these surfers will just see their baskets in different order after a rename :-) Of course, if you display the baskets in alpha order by name, it won't be too much of a shock to them when they are displayed in a

Re: [PHP] changing a key in an array

2003-01-23 Thread David T-G
Chris -- ...and then Chris Boget said... % % So I'm back to the beginning and to funky array wrappers again... I % think these surfers will just see their baskets in different order after % a rename :-) % % Of course, if you display the baskets in alpha order by name, it won't True enough,

RE: [PHP] changing a key in an array

2003-01-23 Thread John W. Holmes
- From: David T-G [mailto:[EMAIL PROTECTED]] Sent: Thursday, January 23, 2003 3:37 PM To: PHP General list Cc: Chris Boget Subject: Re: [PHP] changing a key in an array Chris -- ...and then Chris Boget said... % % So I'm back to the beginning and to funky array wrappers again... I

Re: [PHP] changing a key in an array

2003-01-22 Thread Brent Baisley
I had to do something like this not to long ago. Luckily it hit me that I shouldn't be changing keys, you don't do it in a database, so you really shouldn't do it in an array. I ended up adding a column to my array that contained the name. Then I didn't need to change keys and it worked just

Re: [PHP] changing a key in an array

2003-01-22 Thread David T-G
Brent, et al -- ...and then Brent Baisley said... % % I had to do something like this not to long ago. Luckily it hit me that % I shouldn't be changing keys, you don't do it in a database, so you % really shouldn't do it in an array. Hmmm... Good point. % I ended up adding a column to my

Re: [PHP] changing a key in an array

2003-01-22 Thread Brent Baisley
I'm not sure how you are creating your array, but your resulting array would look something like this: Array ( [name1]=namevalue1 [a1]=Array ( [k1]=value1 [k2]=value2 ) [name2]=namevalue2 [a2]=Array (... You end up with a two dimensional array (avoiding the columns term) that

[PHP] changing a key in an array

2003-01-21 Thread David T-G
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,

Re: [PHP] changing a key in an array

2003-01-21 Thread Jason k Larson
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

Re: [PHP] changing a key in an array

2003-01-21 Thread David T-G
Jason -- ...and then Jason k Larson said... % % 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 fair question :-) I'm writing a picture gallery add-on which will

[PHP] Changing the key

2002-10-31 Thread John Meyer
How do I change the key in an array without having a duplicate key=$value? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

Re: [PHP] Changing the key

2002-10-31 Thread 1LT John W. Holmes
How do I change the key in an array without having a duplicate key=$value? You could maybe use array_flip, change the value, then array_flip again. Or create your new key=value and unset() the old one. $array[$new_key] = $array[$old_key]; unset($array[$old_key]); ---John Holmes... -- PHP