Hi,
How can I sort a multi-dimensional array in a reverse order?
For instance,
$songs = array(
'3' => array('artist'=>'The Smashing Pumpkins', 'songname'=>'Soma'),
'4' => array('artist'=>'The Decemberists', 'songname'=>'The Island'),
'1' => array('artist'=>'Fleetwood Mac', 'songname' =>'Second-hand News'),
'2' => array('artist'=>'Jack Johnson', 'songname' =>'Only the Ocean')
);
print_r($songs);
will result in this,
Array
(
[3] => Array
(
[artist] => The Smashing Pumpkins
[songname] => Soma
)
[4] => Array
(
[artist] => The Decemberists
[songname] => The Island
)
[1] => Array
(
[artist] => Fleetwood Mac
[songname] => Second-hand News
)
[2] => Array
(
[artist] => Jack Johnson
[songname] => Only the Ocean
)
)
but I would like to have it in this order instead,
Array
(
[2] => Array
(
[artist] => Jack Johnson
[songname] => Only the Ocean
)
[1] => Array
(
[artist] => Fleetwood Mac
[songname] => Second-hand News
)
[4] => Array
(
[artist] => The Decemberists
[songname] => The Island
)
[3] => Array
(
[artist] => The Smashing Pumpkins
[songname] => Soma
)
)
I want to keep the key values which are [2],[1],[4],[3] (the original order is [3],[4],[1],[2]).
do I need to write a function to do this?
Many thanks,
Lau