With the following function I sort the posts of RSS ascending.
usort($posts, 'mysort');
function mysort($x, $y) {
return strtotime($y->pubDate) - strtotime($x->pubDate);
}
However some of those feeds have instead of a pubDate tag (for the date), they have a tag named published.
All feeds are saved ine one array. My question is how to satisfy both using my function or another function? Something like these:
return strtotime($y->pubDate OR $y->published) - strtotime($x->pubDate OR $x->published);
Your question is not really clear, but is this what you what?
Basically, I’m using a ternary IF operator that can be read like so:
(if condition)?then do this:else do this;Does it help?
Edit
Small edit based on your question about echoing the value:
The answer depends on which attribute take precedence over the other.. for instance, if pubDate it’s more importante than published, then you’d write something like:
And if it was the other way around:
(changing $x for whatever your object is called ofcourse..)
Does this help?