我有一个看起来像这样的数组:
Array
(
[13] => Array
(
[name] => Blah blah
[description] => Blah blah blah
[parent_group_id] => 8
[display] => Blah : Blah
[stamps] => Array
(
[73] => Array
(
[stamp_id] => 73
[name] => Blah
[is_member] =>
[rank] => 2 <--
[description] => Blah blah blah
[rank_token] => easy
)
[80] => Array
(
[stamp_id] => 80
[name] => Blah
[is_member] =>
[rank] => 1 <--
[description] => Blah blah blah
[rank_token] => medium
)
[73] => Array
(
[stamp_id] => 73
[name] => Blah
[is_member] =>
[rank] => 4 <--
[description] => Blah blah blah
[rank_token] => easy
)
[80] => Array
(
[stamp_id] => 80
[name] => Blah
[is_member] =>
[rank] => 3 <--
[description] => Blah blah blah
[rank_token] => medium
)
)
)
)
但是,我想通过 ['rank'] 持有的数字对这个数组中的对象进行排序,分别是 1、2、3 和 4。(我在代码示例中添加了箭头)所以在使用 usort 之后,我希望一切都按数字顺序排序。所以我希望它看起来像这样:
Array
(
[13] => Array
(
[name] => Blah blah
[description] => Blah blah blah
[parent_group_id] => 8
[display] => Blah : Blah
[stamps] => Array
(
[80] => Array
(
[stamp_id] => 80
[name] => Blah
[is_member] =>
[rank] => 1 <--
[description] => Blah blah blah
[rank_token] => medium
)
[73] => Array
(
[stamp_id] => 73
[name] => Blah
[is_member] =>
[rank] => 2 <--
[description] => Blah blah blah
[rank_token] => easy
)
[80] => Array
(
[stamp_id] => 80
[name] => Blah
[is_member] =>
[rank] => 3 <--
[description] => Blah blah blah
[rank_token] => medium
)
[73] => Array
(
[stamp_id] => 73
[name] => Blah
[is_member] =>
[rank] => 4 <--
[description] => Blah blah blah
[rank_token] => easy
)
)
)
)
我的实际数组要大得多,但它仍然遵循这种模式。