2017-12-29 38 views
0

저는 현재 WordPress 백엔드를 운영 중이며 내 웹 사이트에있는 hastags를 기반으로 한 일부 트윗을 표시하려고합니다. 내가 함께 "추가 배열 예를 들어 주 + 좋아 + 의견에있는 모든 변수를 계산하고 기반의 모든 게시물을 정렬하는 기능을 찾고 이제JSON으로 트윗을 캐치하고 좋아하는 것을 정렬 하시겠습니까?

private function parseRequest($json) { 
    $tmp = $json; 
    $result = array(); 

    if (isset($json['statuses'])) { 
     $tmp = $json['statuses']; 
    } 
    if (isset($tmp) && is_array($tmp)){ 
     foreach ($tmp as $t) { 
      $this->image = null; 
      $this->media = null; 
      $tc = new \stdClass(); 
      $tc->feed_id = $this->id(); 
      $tc->id = $t['id_str']; 
      $tc->type = $this->getType(); 
      $tc->nickname = '@'.$t['user']['screen_name']; 
      $tc->screenname = (string)$t['user']['name']; 
      $tc->userpic = str_replace('.jpg', '_200x200.jpg', str_replace('_normal', '', (string)$t['user']['profile_image_url'])); 
      $tc->system_timestamp = strtotime($t['created_at']); 
      $tc->text = $this->getText($t); 
      $tc->userlink = 'https://twitter.com/'.$t['user']['screen_name']; 
      $tc->permalink = $tc->userlink . '/status/' . $tc->id; 
      $tc->media = $this->getMedia($t); 
      @$tc->additional = array('shares' => (string)$t['retweet_count'], 'likes' => (string)$t['favorite_count'], 'comments' => (string)$t['reply_count']); 
      if ($this->isSuitablePost($tc)) $result[$tc->id] = $tc; 
     } 
    } 
    return $result; 
} 

: 일반 API 요청 및 데이터베이스 저장을 위해, 나는이 기능을 사용 . 결과 수에 나는 표준 워드 프레스 SQL 데이터베이스를 사용하고 내가 해결책을 찾을 수 없거나 그냥 장님 관해서

감사를

답변

0

당신은 간단한 usort 기능을 사용할 수 있습니다..

을3210
usort($tc, function($a, $b) { 

    $a_sum = array_sum($a->additional); 
    $b_sum = array_sum($b->additional); 

    if ($a_sum == $b_sum) { 
     return 0; 
    } 

    return ($a_sum < $b_sum) ? -1 : 1; 
});