two php arrays - sort one array with the value order of another
Posted
by
Tisch
on Stack Overflow
See other posts from Stack Overflow
or by Tisch
Published on 2011-01-09T22:26:49Z
Indexed on
2011/01/09
22:53 UTC
Read the original article
Hit count: 238
Hi there,
I have two PHP arrays like so:
- Array of X records containing the ID of Wordpress posts (in a particular order)
- Array of Wordpress posts
The two arrays look something like this:
Array One (Sorted Custom Array of Wordpress Post IDs)
Array (
[0] => 54
[1] => 10
[2] => 4
)
Array Two (Wordpress Post Array)
Array (
[0] => stdClass Object
(
[ID] => 4
[post_author] => 1
)
[1] => stdClass Object
(
[ID] => 54
[post_author] => 1
)
[2] => stdClass Object
(
[ID] => 10
[post_author] => 1
)
)
I would like to sort the array of wordpress posts with the order of the ID's in the first array.
I hope this makes sense, and thanks in advance of any help.
Tom
edit: The server is running PHP Version 5.2.14
© Stack Overflow or respective owner