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

Filed under:
|
|

Hi there,

I have two PHP arrays like so:

  1. Array of X records containing the ID of Wordpress posts (in a particular order)
  2. 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

Related posts about php

Related posts about arrays