Member Avatar for diafol

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.

Recommended Answers

All 2 Replies

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.

Member Avatar for diafol

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.