Pergunta

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/

Foi útil?

Solução

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.

Outras dicas

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']);
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top