sorting numerically with strings possible?
Posted: Tue Jun 03, 2008 4:12 pm
Hi, I have a list of random numbers I want listed numerically but some of them contain alphabetical characters. I tried sort($array, SORT_NUMERICAL); and sort($array, SORT_STRING); but neither gave me what I was hoping for.
here is a sample
I'll show you my results using the different sorts and what I am hoping for
What I want is the following
I hope this is making sense, lol.
Thanks,
here is a sample
Code: Select all
$boItems = "0207000000,1000WH420C,1188000000,1801WH40BD,0229US0000,1000WH480C,1190000000,1803BE48DF,0306003800,1000WH500C,1204020000,91950040DD,
0307003800,1006PW360D,1207LLMM00,919500440F,0333000000,1006PW420D,1207MM0000,919502380D,0606000000,1006PW440F,1227000000,919502440C,
0607000000,1006PW44DD,1238000000,1801WH38BD,1182RE0200,0631000000,1801WH36BD,1182QE0200,0623MM0000,1801CF40BD,1142000000,0623LLMM00, 1801CF38DF,1109000000,0622BL0000,126502480C,1056000000,0621010000,126502440C,1048000000,0616000000,0610000000,1012000000,126502380C";
$boArray = explode(',',$boItems);
sort($boArray);
Code: Select all
Sort($array, SORT_STRING)
0307003800
0607000000
1801CF38DF
0207000000
0229US0000
0306003800
0333000000
0606000000
0610000000
0616000000
0621010000
0622BL0000
Code: Select all
sort($array)
1801CF38DF
0207000000
0306003800
0307003800
0333000000
0606000000
0607000000
0229US0000
0610000000
Code: Select all
sort($array, SORT_NUMERIC)
0229US0000
0622BL0000
0623MM0000
0623LLMM00
1000WH500C
1000WH480C
1000WH420C
1207LLMM00
1803BE48DF
91950040DD
126502380C
126502440C
126502480C
0207000000
Code: Select all
0207000000
0229US0000
0306003800
0307003800
0607000000
0623LLMM00
1000WH420C
1188000000
126502380C
1801WH36BD
919500440F
Thanks,