Jump to content

[SOLVED] PHP Array Sort


aeonsky

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.