Soundcloud跟踪按时间戳排序的评论

时间:2012-08-21 09:52:16

标签: comments soundcloud

有没有办法让/tracks/{id}/commentstimestamp asc/desc订购的曲目获得?默认顺序是created_at属性降序。

1 个答案:

答案 0 :(得分:2)

我不知道soundcloud是否可以对请求进行排序,但您可以将请求的响应排序为usort()strnatcmp()自然顺序字符串。
像这样:

function orderBy($data, $field) { 
        $code = "return strnatcmp(\$a['$field'], \$b['$field']);";
        usort($data, create_function('$a,$b', $code)); 
        return $data; 
} 

// Get comments
$comments = json_decode($soundcloud->get('tracks/{id_track}/comments'), true);

// Order comments by 'timestamp'
$data = orderBy($comments, 'timestamp');