0

以下のような配列があります。object parameter に基づいてこれらを並べ替えたいと思いましたa_weight。私はこれを行うことができません.2番目に、このキー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
        )
4

1 に答える 1

1

機能を使用する必要がありuasortます。詳細はhttp://php.net/manual/en/function.uasort.phpをご覧ください

あなたの場合の例は次のとおりです。

function mysort($a, $b){
    return $a->a_weight < $b->a_weight ? -1 : 1;
}
$objects = uasort($objects, 'mysort');
于 2012-10-16T06:01:13.167 に答える