Re: changing a key in an array
| From: | David T-G | Date: | Thu, 23 Jan 2003 18:26:13 +0000 |
| Subject: | Re: changing a key in an array | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-132879@lists.php.net to get a copy of this message | ||
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 links or pop up would be the element
% number of the array item containing the desired basket.
OK... Then, of course, I'd have to do name->number mapping so that I can
present the surfer with the name that he chose rather than just a number,
but that could be done, too.
% To extract a basket by name I would say you could use array_search, but
% in looking into that function it appears to have changed through recent
% versions of PHP. In PHP 4.1 it doesn't search multi-dimensional arrays,
% I'm not sure about in 4.2.
Makes it trickier :-)
%
% But it's easy enough to create your own function to search the array.
Right.
% And you are right, the setup I recommended can get a bit kludgy. But if
% you "denormalize" the array structure it can get easy again. Just make
% the first element for each basket the name of basket.
% $baskets[] = array("basketname1","item1","item2");
% $baskets[] = array("basketname2","item1","item2","item3");
% $baskets[] = array("basketname3","item1","item2",...);
Hmmm... I tried something like this and it got ugly. I could try again,
except now it looks like I won't have to.
%
% You can use sort() to sort the array.
Right.
%
% Hope that helps and sorry about steering you down the difficult path
% first.
It's quite informative, and I still need a lot of that, and the tough
path is no problem :-) Thanks for all of the input!
HAND
:-D
--
David T-G * There is too much animal courage in
(play) davidtg@justpickone.org * society and not sufficient moral courage.
(work) davidtgwork@justpickone.org -- Mary Baker Eddy, "Science and Health"
http://justpickone.org/davidtg/ Shpx gur
Pbzzhavpngvbaf Qrprapl Npg!