Jump to content

Recommended Posts

Hello, I'm back!

 

When I get an array of directory contents, all folders are numbers. First folder is "004" and the second folder is "055".

 

When I print the array, it puts 004 first and then 055.

 

But if I make the folder "4" and "055", it puts the "055" first, why?

 

Thanks very much for the time and consideration!

Link to comment
https://forums.phpfreaks.com/topic/83941-solved-php-array-sort/
Share on other sites

i havn't worked with array sort much  , but as you are saying it echo 055 first than 4 . i guess  it is because of the starting digits , have you ever seen this kind of sorting :

 

0 1 10 11 12 12 13 2 3 4 5 6 7 8 9

 

can you get the point ? although 10 11 12 ... is more than 9 but they are sort first , in other words it won't check what number is bigger, it check the first digit of a number ,then goes to second . that's why 4 is bigger than 055 , cause it begins with 4, but 055 begin with 0 .

 

i hope this is what you were asking .

Link to comment
https://forums.phpfreaks.com/topic/83941-solved-php-array-sort/#findComment-427168
Share on other sites

Hmmm, that makes a lot of sense now. I'm just coding on a local server and Windows sorts it by value, but I checked now, cPanel sorts it the same way PHP sorts it.

 

So now it means I have sprintf("%03d") every single directory now? O.o Oh well...

 

Thanks a bunch!

Link to comment
https://forums.phpfreaks.com/topic/83941-solved-php-array-sort/#findComment-427169
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.