排序规则,有备注的排前面,没备注的排后面,然后按字母排序。ksort非常常用。关键是找到那个适合排序的key
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
//联系人排序
public
function
get_persort(
$person
){
$arrPer
=
array
();
//有备注
$arrAuto
=
array
();
//无备注的
foreach
(
$person
as
$value
) {
$value
[
'contactmail'
] =
strtolower
(
$value
[
'contactmail'
]);
//同一小写,避免大小写影响排序
if
(
empty
(
$value
[
'contactname'
])){
$arrAuto
[
$value
[
'contactmail'
]] =
$value
;
}
else
{
$arrPer
[
$value
[
'contactmail'
]] =
$value
;
//邮箱名是唯一的
}
}
ksort(
$arrPer
);
ksort(
$arrAuto
);
return
array_values
(
array_merge
(
$arrPer
,
$arrAuto
));
//合并数组,去掉key(js没有关联数组,只有索引数组)
}
|