ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Maybe I'm not understanding what you're trying to do, but PHP has just about every array sorting function you could ever possibly want.
Maybe if you could show me what some example data looks like, and what it should look like after it has been sorted, I can show you how to best go about doing that.
I am trying to list all the files in a specified directory and get them to be sorted alphabetically, ignoring case. For example, the filename Me2.txt would come BEFORE me10.txt.
if i get u right there is a logical mistake in your code. while u read the directory u have to put the name of each file into an array. When youre done u can sort the array.
Right now youre sorting while still reading the directory. this cannot work.
btw file10 comes before file2 in ascii-"alphabet" as ascii cannot count.
Even if I put the natcasesort function after the array has finished reading, it doesn't make a difference to the result.
Graemef:
The array sorting test code works as it should. But I am using $key => $value pairs in my array. Should this make any difference in how I approach sorting the array?
For example, could the natcasesort function be lost as to what to sort the array by?
I'm not certain what you are holding but could you get the files sort them and then copy into another array, collecting the other information as you go?
The above lines are the key. These lines make a copy of the array, change it to lowercase, THEN sort it (array_multisort), THEN change it back to uppercase.
This is the only solution I have been able to find and CONFIRM that works with multi-dimensional arrays.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.