php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #7354 Feature Request: sort on single element arrays
Submitted: 2000-10-19 18:23 UTC Modified: 2003-08-14 02:09 UTC
From: charlie at screaming-penguin dot com Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: 4.0.3pl1 OS: Linux 2.2.x
Private report: No CVE-ID: None
 [2000-10-19 18:23 UTC] charlie at screaming-penguin dot com
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.

This makes sense as far as 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.  

It would be nice if sort would sort single element arrays.  


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-08-14 02:09 UTC] sniper@php.net
I don't know when this has been fixed but in latest
stable CVS this works as you expect. (single element array key is reset with sort())

 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Thu Feb 12 12:00:01 2026 UTC