1. 程式人生 > >二維數組排序

二維數組排序

二維 col urn res div class color 升序 排序

//二維數組排序, $arr是數據,$keys是排序的健值,$order是排序規則,1是升序,0是降序
function array_sort($arr, $keys, $order = 0)
{
    if (!is_array($arr)) {
        return false;
    }
    $keysvalue = array();
    foreach ($arr as $key => $val) {
        $keysvalue[$key] = $val[$keys];
    }
    if ($order == 0) {
        asort($keysvalue
); } else { arsort($keysvalue); } reset($keysvalue); foreach ($keysvalue as $key => $vals) { $keysort[$key] = $key; } $new_array = array(); foreach ($keysort as $key => $val) { $new_array[$key] = $arr[$val]; } return $new_array; }

二維數組排序