-1

Cassandra Json 格式看起来像这样

    "recommendResult":[{
       "mediaId":"",
       "mediaEntry":[{
           "user1":{
               "name":"sooin",
               "rating":"3",
               "views":"2",
               "like":"ture",
               "comment":"good"
           },
           "user2":{
               "name":"sara",
               "rating":"1",
               "views":"4",
               "like":"ture",
               "comment":"good!"
           }
       }],
       "view":"4",
       "rating":"4",
       "like":"10",
       "smallUrl":"/photo/smallUrl",
       "largeUrl":"/photo/largeUrl",      
       "title":"aaaa"                  
    }]

这是我的php代码

$rows=$column_family->get_range();
$count=0;

    foreach($rows as $key => $columns) {

     $returnkey[$count]=array('mediaId'=>$key,   
              'columns'=>$columns,'user'=>array_slice($columns,1,2));
     $count++;
}
natcasesort($returnArray['key']['comment']['photoInfo']['view']);
print_r($returnArray['key']['comment']['photoInfo']['view']);

我正在尝试根据视图进行排序。我尝试使用 natcasesort 但它不起作用。任何想法。谢谢你。

4

1 回答 1

0

PHP doesn't have a built-in sorting algorithm that will sort multidimensional arrays based on a certain key/value pair. You should write your own sorting algorithm to handle this data.

Here's somewhere to get started (all of these can easily be modified to work with your particular array):

Comparison of sorting algorithms

于 2012-08-13T21:15:36.200 回答