我有一个包含简单对象的数组。我拥有的数组如下所示:
[posts] => Array
(
[0] => WP_Post Object
(
[ID] => 4
[post_title] => Post #4
...
)
[1] => WP_Post Object
(
[ID] => 100
[post_title] => Post #100
...
)
[2] => WP_Post Object
(
[ID] => 1
[post_title] => Post #1
...
)
[3] => WP_Post Object
(
[ID] => 21
[post_title] => Post #21
...
)
)
我还有一个数组,其中包含第一个数组帖子 ID,按我喜欢显示该帖子的顺序排列。可以说数组映射是这样的:
[map] => Array
(
[0] => 4
[1] => 21
[2] => 100
[3] => 1
)
现在算式。我可以使用 Map 数组作为映射,根据每个对象 ID 属性对包含对象的数组进行排序,以获得如下所示的结果:
[posts] => Array
(
[0] => WP_Post Object
(
[ID] => 4
[post_title] => Post #4
...
)
[1] => WP_Post Object
(
[ID] => 21
[post_title] => Post #21
...
)
[2] => WP_Post Object
(
[ID] => 100
[post_title] => Post #100
...
)
[3] => WP_Post Object
(
[ID] => 1
[post_title] => Post #1
...
)
)