note 9170 added to sort
| From: | charlie at screaming-penguin dot com | Date: | Thu, 19 Oct 2000 22:21:18 +0000 |
| Subject: | note 9170 added to sort | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-6719@lists.php.net to get a copy of this message | ||
sort() does not appear to work for arrays that have only a single element. I am using dynamically
built arrays and when an array happens to have a single element it does not get touched by sort.
Why would I want to sort an array with a single element? Because I want the indeces reset, not just
the values sorted. If an array has this structure:
array(1) { [3]=> string(9) "Baltimore"
then it will not be touched at all by sort and will not be re-indexed to start at 0.
To deal with this you can check each dynamically assigned array and count() the elements, if the
array has only a single element, then it can be manually re-indexed.
This is a work around, but it would be nice if sort would sort single element arrays and or if the
manual mentioned this feature-issue.
http://www.php.net/manual/function.sort.php