有没有办法让/tracks/{id}/comments
为timestamp asc/desc
订购的曲目获得?默认顺序是created_at
属性降序。
答案 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');