0

I'm trying to sort an array which contains objects, but have hit a wall. I have a number of feeds that are placed into objects (WM). The feeds are placed in the order that they're loaded. I want them to be ordered w.r.t. pubDate. I'd rather not recode the whole thing, just apply a sort if possible.

Here's the print_r($myarray) output:

Array
(
    [0] => WM Object
        (
            [link] => http://www.xxxx.co.uk/91466-24704797/
            [title] => TITLE1
            [pubDate] => Wed, 16 Sep 2009 10:55:00 GMT
            [guid] => http://www.xxxx.co.uk/91466-24704797/
            [description] => Just a desc 1
            [category] => Blog
        )

    [1] => WM Object
        (
            [link] => http://www.xxxx.co.uk/91466-24704799/
            [title] => TITLE 2
            [pubDate] => Wed, 16 Sep 2009 10:57:00 GMT
            [guid] => http://www.xxxx.co.uk/91466-24704799/
            [description] => Just a desc 2
            [category] => News
        )

    [2] => WM Object
        (
            [link] => http://www.xxxx.com/rss/
            [title] => TITLE 3
            [pubDate] => Wed, 16 Sep 2009 09:55:00 GMT
            [guid] => http://www.xxxx.com/rss/
            [description] => Just a desc 3
            [category] => Story
        )

I can change the pubDate to unix timestamp - so the format's not a problem. So, from the dates, reordering: 0=>object2, 1=>object1,2=>object3.

I can access individual data via $array[$counter]->pubDate .

I've been staring at this for a while, asort, ksort arrggghhhhh! I think my brain is bleeding.

Thanks in advance.

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by diafol
0

I would suggest trying the following 3 functions:

array_multisort()
arsort()
asort()

I can't tell for sure which one or if any will work because there isn't an example for me to test.

0

OK cheers c, will give them a go - but I'm gonna wait till tomorrow or I'm gonna explode!!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.