2011-09-18 79 views
0

我将如何创建一个函数来采取使用TwitterOAuth对象由亚伯拉罕·威廉姆斯,叽叽喳喳的鸣叫数组能够鸣叫e.g比较数组的值,例如a与b和c以及d?

鸣叫随着资料Tweet B带分享Tweet C的阵列比较等等?

require_once('Twitter/twitteroauth/twitteroauth.php'); 
require_once('Twitter/Twitter_Config.php'); 

$userTimeline = $connection->get('statuses/user_ti'); 

function createAnArrayofTweetTimes($timeline) 
{ 
    $tweetTimes = array(); 

    foreach ($timeline as $tweet) { 
     $tweettext = strtolower($tweet->text); 
     if (stristr($tweettext, '#edgarsclub')) { 
      array_push($tweetTimes, $tweet->created_at); 
      array_push($tweetTimes, 1); 
      echo $tweet->created_at; 
     } 
    } 
    return $tweetTimes; 
} 

我想利用这个值,这将是一个数组

$tweetTimes = $createAnArrayofTweetTimes($usertimeline) 

而且每次鸣叫用后面的功能下一个比较。

function tweetTime($x, $y) 
{ 
    //THIS FUNCITON WILL COMPARE TWEETS WITH ONE ANOTHER 
    //TAKE PRECEDING TWEET AND COMPARE WITH SUCCEEDING TWEET 
    //IF LESS THEN 24 RETURN FALSE 

    $currentTime = strtotime($currentTime); 
    $tweetTime = strtotime($tweetTime); 
    $timeInSeconds = $currentTime - $tweetTime; 

    if ($timeInSeconds > 84600) { 
     return true; 
    } else { 
     return false; 
    } 
} 
+1

你有一个不完整的行,你需要通过“比较推文数组”来定义你的意思。 –

+0

@Tomalak Geret'kal我更新了文字。 – Aaron

回答

1

看到一个建议的方法如下:

function compareTweets($tweetTimes) { 
    for ($i=0; i<count($tweetTimes)-1; $i++) { 
     if (tweetTime($tweetTimes[$i], $tweetTimes[$i+1]) { 
      //do what you want when the tweet time is more than 24h 
     } 
     else { 
      //do what you want when the tweet time is less than 24h 
     } 
    } 
} 

我希望这有助于。如果不是,请再次发帖。祝你好运!

+1

谢谢downvotes ...我的代码错了 - 我更新了变量的名称,并在代码中用“+”替换了“=”。它现在应该工作....我希望...:O) – jdias

相关问题