RE: [PHP] Sorting problem
| From: | Daryl Meese | Date: | Sat, 28 Jun 2003 15:01:52 +0000 |
| Subject: | RE: [PHP] Sorting problem | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-153266@lists.php.net to get a copy of this message | ||
asort should do the trick.
Good Luck
Daryl
-----Original Message-----
From: Sparky Kopetzky [mailto:sparkyk@blackmesa-isp.net]
Sent: Saturday, June 28, 2003 9:50 AM
To: Daryl Meese; David Otton
Cc: PHP General
Subject: Re: [PHP] Sorting problem
Yes, I need the key to remain associated with the value as the key links the
value to a directory. Can't have files going into the wrong places. So if
asort does the job, I'll try that and see if the code breaks or not.
Sparky
----- Original Message -----
From: "Daryl Meese" <darylm@magiasoftware.com>
To: "David Otton" <phpmail@jawbone.freeserve.co.uk>
Cc: "PHP General" <php-general@lists.php.net>
Sent: Friday, June 27, 2003 19:17
Subject: RE: [PHP] Sorting problem
> David,
>
> See what you mean. I guess we need some clarification on the original
> question?
>
> Thanks
>
> -----Original Message-----
> From: David Otton [mailto:phpmail@jawbone.freeserve.co.uk]
> Sent: Friday, June 27, 2003 8:09 PM
> To: Daryl Meese
> Cc: PHP General
> Subject: Re: [PHP] Sorting problem
>
>
> On Fri, 27 Jun 2003 19:45:27 -0500, you wrote:
>
> >ckeck out asort and arsort
>
> I'm looking...
>
> My understanding was that the original poster wanted to sort an array by
> "value"|"key" ("sort an array and have the key 'follow' the
> value")
>
> eg
>
> 'pear' => 'green',
> 'orange' => 'orange',
> 'banana' => 'yellow',
> 'tangerine' => 'orange',
> 'apple' => 'green'
>
> becomes
>
> 'apple' => 'green',
> 'pear' => 'green',
> 'orange' => 'orange',
> 'tangerine' => 'orange',
> 'banana' => 'yellow'
>
> However, asort() produces (here, anyway) :
>
> 'apple' => 'green',
> 'pear' => 'green',
> 'tangerine' => 'orange',
> 'orange' => 'orange',
> 'banana' => 'yellow'
>
> It's not explicitly stated in the manual, but it seems that when the
values
> are the same, the order of the keys associated with them is not defined.
> Even if it happened to produce correct output on one system, I wouldn't
> trust it in production code.
>
> Of course, I could have mis-read the original question... I can see how
> "have the key 'follow' the value" could be read as "have the key
> maintain
> it's association with the value".
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>