php中用户自定义排序

php中数组用户自定义排序函数有usort和uasort,前者键值重新排列,后者保持原数组的键值。

举例usrot:

usort($filterArr, 'sortArr');
function sortArr($a, $b) {
    $aa = explode(',', $a);
    $bb = explode(',', $b);
    if ($aa[0] == $bb[0]) return 0;
    return ($aa[0] < $bb[0]) ? -1 : 1;
}

如果是类中调用usrot的话,比如方法放在当前类中,则调用方式如下:

usort($filterArr, array($this,'sortArr'));
原文地址:https://www.cnblogs.com/hpze2000/p/3414210.html