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
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
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
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
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'];
%
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']
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
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,
-
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
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
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
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
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
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
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
15 matches
Mail list logo