php根据字母进行数组排序

php根据字母进行数组排序,下面是具体的实例: var cityList=[{ "enValue": "shijiazhuang", "key": 37, "sort": 0, "value": "石家庄市"}, { "enValue": "tangshan", "key": 61, "sort": 0, "value": "唐山市"}, { "enValue": "qinhuangdao", "key": 77, "sort": 0, "value": "秦皇岛市"}]function letterSo

php根据字母进行数组排序,下面是具体的实例:
var cityList=[{
    "enValue": "shijiazhuang",
    "key": 37,
    "sort": 0,
    "value": "石家庄市"
}, {
    "enValue": "tangshan",
    "key": 61,
    "sort": 0,
    "value": "唐山市"
}, {
    "enValue": "qinhuangdao",
    "key": 77,
    "sort": 0,
    "value": "秦皇岛市"
}]
function letterSort(property) {
          return function (a, b) {
                   var value1 = a[property];
                   var value2 = b[property];
                   if (value1 < value2) {
                         return -1;
                    } else if (value1 < value2) {
                        return 1;
                    } else {
                        return 0
                    }
           }
}
 var Citys=cityList.sort(letterSort('enValue'))
console.log(Citys)
[{enValue: "shijiazhuang", key: 37, sort: 0, value: "石家庄市"},
 {enValue: "tangshan", key: 61, sort: 0, value: "唐山市"},
 {enValue: "qinhuangdao", key: 77, sort: 0, value: "秦皇岛市"}]

本文标题为:php根据字母进行数组排序

基础教程推荐