RE: [PHP] Sort an array by it's values SOLVED
| From: | Jeff McKeon | Date: | Mon, 26 Apr 2004 14:19:03 +0000 |
| Subject: | RE: [PHP] Sort an array by it's values SOLVED | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-184651@lists.php.net to get a copy of this message | ||
Never Mind,
I had mixed upper and lowercase names in my test...
Thanks,
Jeff
> -----Original Message-----
> From: Jeff McKeon
> Sent: Monday, April 26, 2004 10:14 AM
> To: Michal Migurski
> Cc: php-general@lists.php.net
> Subject: RE: [PHP] Sort an array by it's values
>
>
> > asort() /does/ sort by element value, it just maintains index
> > association. Plain old sort() does not.
>
> Ok, how would I then print out the array in the newly sorted order?
>
> $names[]= alice;
> $names[]= candy;
> $names[]= dave;
> $names[]= bob;
>
> While(list($key,$element)=each($names))
> {
> echo"$key, $element<BR>";
> }
>
> Returns:
>
> 1,alice
> 2,candy
> 3,dave
> 4,bob
>
> Asort($names);
> While(list($key,$element)=each($names))
> {
> echo"$key, $element<BR>";
> }
>
> Also returns:
> 1,alice
> 2,candy
> 3,dave
> 4,bob
>
> What am I missing here?
>
> Jeff
>
>
> > -----Original Message-----
> > From: Michal Migurski [mailto:mike@teczno.com]
> > Sent: Monday, April 26, 2004 10:09 AM
> > To: Jeff McKeon
> > Cc: php-general@lists.php.net
> > Subject: Re: [PHP] Sort an array by it's values
> >
> >
> > > Is there a command similar to asort() that will sort the
> > elements of
> > > an array not by their key values but by the element values?
> >
> > asort() /does/ sort by element value, it just maintains index
> > association. Plain old sort() does not.
> >
> > If you actually want to sort by key value, you want ksort().
> >
> > There's a complete list of all the sort functions at:
> > http://php.net/manual/en/ref.array.php
> >
> >
> ---------------------------------------------------------------------
> > michal migurski- contact info and pgp key:
> > sf/ca http://mike.teczno.com/contact.html
> >
> >
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>