Reputation: 2935
How can i sort this array by $data['response']['games'][x]['name']
alphabetical from A-Z?
I have tried already array_multisort()
but didn't understand this function at all.
Hope you can help me - googled and searched this but didn't found any solution for my problem.
Edit: link updated.
Code: https://github.com/GabrielWanzek/GWSteamLib/
Upvotes: 0
Views: 463
Reputation: 51
Try following code:
$games = $data['response']['games']; // is array
usort($games, 'compareName');
var_dump($games);
# want to change $data?
# $data['response']['games'] = $games;
function compareName($a1, $a2) {
return strcmp($a1['name'], $a2['name']);
}
Upvotes: 1
Reputation: 5151
You can achieve this with usort()
, which allows you to define a custom comparison function:
usort($data['response']['games'], function($a, $b) {
return strcmp($a['name'], $b['name']);
});
Note that $data
is an object of type stdClass
; it is not an array.
Upvotes: 1