Here's the example array, $SocialPosts
:
Array(
[18] => SocialPost Object
(
[time] => 20140415
[url] => http://www.twitter.com/twitterapi
[copy] => We have agreed to acquire @gnip, welcome to the flock! https://t.co/fXrE36fjPZ
[image] =>
)
[19] => SocialPost Object
(
[time] => 20140409
[url] => http://www.twitter.com/twitterapi
[copy] => RT @twittersecurity: http://t.co/OOBCosuKND & http://t.co/oPmJvpbS6v servers were not affected by OpenSSL vulnerability CVE-2014-0160 http:…
[image] =>
)
[20] => SocialPost Object
(
[time] => 20140602
[url] => http://www.facebook.com/19292868552
[copy] => Our June 2014 events calendar is up! Join us at events around the world this month, and learn how to build, grow, and monetize your apps with Facebook: https://developers.facebook.com/blog/post/2014/06/02/june-2014-developer-events-for-facebook-and-parse/
[image] => https://fbexternal-a.akamaihd.net/safe_image.php?d=AQBMV0YW8BCmCBMB&w=154&h=154&url=https%3A%2F%2Ffbstatic-a.akamaihd.net%2Frsrc.php%2Fv2%2Fy6%2Fr%2FYQEGe6GxI_M.png
)
)
I'm creating each SocialPost Object
by using data from their respective APIs (Twitter, Facebook), and then adding each SocialPost Object
to a SocialPosts
array.
I tried the following rsort
so that I could list them all together in reverse order by the [time]
property:
function cmp($a, $b){
return strcmp($a->time, $b->time);
}
rsort($socialPosts, "cmp");
However, it's oddly enough sorting the Twitter posts in the right order, followed by the Facebook posts in the right order, in what looks like two separate sorts. It should order them together regardless source in the correct order according to the [time]
value.
It's also worth nothing that after adding each SocialPost
to the array, I run a loop to format and then update the [time]
property correctly, since Twitter and Facebook provided the time detail in different formats. Here's that snippet as well:
foreach($socialPosts as $socialPost){
$date_string = $socialPost->time;
$date = new DateTime($date_string);
$date->setTimezone(new DateTimeZone('America/New_York'));
$formatted_date = $date->format('Ymd');
$socialPost->time = $formatted_date;
}
Any ideas as to what could be going wrong?