如何通过" department_id"对这种类型的关联数组进行排序

时间:2015-05-04 06:00:37

标签: sorting

Array
(
    [0] => stdClass Object
        (
            [id] => 16
            [department_id] => 4
            [employee_status] => 1


        )

    [1] => stdClass Object
        (
            [id] => 17
            [department_id] => 8
            [employee_status] => 1
        )

)

1 个答案:

答案 0 :(得分:2)

我找到了一个排序对象数组的解决方案

function cmp($a, $b) {
     return $b->department_id - $a->department_id;
}
$sirtedArray=usort($employeelist, "cmp");