Php 当2个属性具有相同值时对数组中的对象进行排序

Php 当2个属性具有相同值时对数组中的对象进行排序,php,multidimensional-array,Php,Multidimensional Array,我有如下数组。我想根据对象参数a\u权重对它们进行排序。我不能这样做,第二件事是这个键a_weight可以在不同的对象中具有相同的值,如下图所示。有人帮我整理一下吗 [0] => stdClass Object ( [a_priority] => 1 [a_roleobjectid] => 1 [a_roleid] => 1 [a_objectid] =>

我有如下数组。我想根据对象参数
a\u权重
对它们进行排序。我不能这样做,第二件事是这个键
a_weight
可以在不同的对象中具有相同的值,如下图所示。有人帮我整理一下吗

[0] => stdClass Object
        (
            [a_priority] => 1
            [a_roleobjectid] => 1
            [a_roleid] => 1
            [a_objectid] => 1
            [a_objecttypeid] => 2
            [a_name] => Object Type
            [a_path] => abc/b
            [a_createddate] => 2012-10-08 11:00:00
            [a_createdby] => 1
            [a_modifieddate] => 2012-10-08 11:05:50
            [a_modifiedby] => 1
            [a_weight] => 1
            [a_cancreate] => 1
            [a_canread] => 1
            [a_canupdate] => 1
            [a_candelete] => 1
            [a_canprint] => 1
            [a_canexport] => 1
        )

    [1] => stdClass Object
        (
            [a_priority] => 1
            [a_roleobjectid] => 2
            [a_roleid] => 1
            [a_objectid] => 2
            [a_objecttypeid] => 2
            [a_name] => Object
            [a_path] => abc/a
            [a_createddate] => 2012-10-08 11:00:00
            [a_createdby] => 1
            [a_modifieddate] => 2012-10-08 11:05:50
            [a_modifiedby] => 1
            [a_weight] => 3
            [a_cancreate] => 1
            [a_canread] => 1
            [a_canupdate] => 1
            [a_candelete] => 1
            [a_canprint] => 1
            [a_canexport] => 1
        )
[2] => stdClass Object
        (
            [a_priority] => 1
            [a_roleobjectid] => 3
            [a_roleid] => 1
            [a_objectid] => 3
            [a_objecttypeid] => 2
            [a_name] => Role
            [a_path] => abc/r
            [a_createddate] => 2012-10-08 11:00:00
            [a_createdby] => 1
            [a_modifieddate] => 2012-10-08 15:19:02
            [a_modifiedby] => 1
            [a_weight] => 1
            [a_cancreate] => 1
            [a_canread] => 1
            [a_canupdate] => 1
            [a_candelete] => 1
            [a_canprint] => 1
            [a_canexport] => 1
        )

您需要使用
uasort
功能。更多信息请访问

您的案例示例如下:

function mysort($a, $b){
    return $a->a_weight < $b->a_weight ? -1 : 1;
}
$objects = uasort($objects, 'mysort');
函数mysort($a,$b){
返回$a->a\U重量<$b->a\U重量?-1:1;
}
$objects=uasort($objects,'mysort');