我分揀使用的值按字母順序的陣列,所述陣列是如下:排序使用值字母字符串數組,並考慮值的情況下,在PHP
Array (
[0] => test This
[1] => This test
[2] => again this test
[3] => test again this
[4] => this test again
[5] => Dallas University Texas
[6] => Texas Dallas University
[7] => University Texas Dallas
[8] => dallas University Texas
[9] => Texas dallas University
[10] => University Texas dallas
[11] => Johnson Johnson
[12] => Johnson Johnson
)
預期輸出時,我的排序應該儘可能如下:
again this test
dallas University Texas
Dallas University Texas
Johnson Johnson
test again this
test This
this test again
Texas dallas University
Texas Dallas University
This test
University Texas dallas
University Texas Dallas
我的代碼如下:
比較
function compareValues($a,$b) {
if ($a == $b) {
return 0;
}
return ($a < $b) ? -1 : 1;
}
function transform($input){
return usort($input,array($input,"compareValues"));
}
print_r($transform($input));
我的當前輸出不能按字母順序排列所有值並且不區分大小寫,它只能生成部分有序的數組。它應該是比較器功能有一些故障。
可以按字母順序排序以及情況?@ agha-umair-ahmed – leboMagma
不會照顧案例,因爲你想 – madforstrength
我試圖asort(),但它並不適合我madforstrength – leboMagma