我有一个包含多个键的数组,
Array
(
[0] => stdClass Object
(
[type] => ab_micro_list
[title] => Testing List
[user_id] => 70318
[micro_list_id] => 390
)
[1] => stdClass Object
(
[type] => ab_micro_list
[title] => Testing List
[user_id] => 70319
[micro_list_id] => 390
)
)
基于这个数组我需要像这样创建数组
Array
(
['Testing List'] => Array
(
['users'] => Array
(
[0] => 70318
[1] => 70319
)
)
)
有没有办法实现这一目标。如果有人有任何建议,请分享。
答案 0 :(得分:2)
试试这个。
int[] order = new[] {3, 1, 2}; //1 is third, 2 is first, 3 is second.
items = items.OrderBy(x => order[x.Id - 1]);