我尝试按名称对此数组进行排序,但我编写的函数不起作用
{
"response": {
"game_count": 175,
"games": [
{
"appid": 4000,
"name": "Garry's Mod",
"playtime_forever": 4040,
"img_icon_url": "4a6f25cfa2426445d0d9d6e233408de4d371ce8b",
"img_logo_url": "93c9364c3942223ab66195182fe1982af8a16584",
"has_community_visible_stats": true
},
按名称排序,位于第三级
我试过了:
function val_sort($array,$key) {
foreach($array as $k=>$v=>$g){
$b[] = strtolower($v[$key]);
}
SORT_ASC($b);
foreach($b as $k=>$g=>$v) {
$c[] = $array[$k];
}
return $c;
}
$sorted = val_sort($array, 'name');
但这对我没有用。 我希望你能帮助我^^
答案 0 :(得分:0)
将foreach与usort结合使用:
foreach ($yourArray["response"] as $key => &$subarray) {
usort($subarray, function($a, $b) {
return $a['name'] <= $b['name'];
});
}
print_r($yourArray); //now it's sorted