Possible Duplicate:
Sorting a multidimensional array in PHP?

   $songs =  array(
    '1' => array('artist'=>'The Smashing Pumpkins', 'songname'=>'Soma'),
    '2' => array('artist'=>'The Decemberists', 'songname'=>'The Island'),
    '3' => array('artist'=>'Fleetwood Mac', 'songname' =>'Second-hand News')
);

Answer should come like this:

   Array(
[0] => Array
    (
        [artist] => Fleetwood Mac
        [song] => Second-hand News
    )

[1] => Array
    (
        [artist] => The Decemberists
        [song] => The Island
    )

[2] => Array
    (
        [artist] => The Smashing Pumpkins
        [song] => Cherub Rock
    )
)

Please help me on this.

share|improve this question

78% accept rate
feedback

closed as exact duplicate by Felix Kling, deceze, Stefan Gehrig, Yoshi, VolkerK Aug 4 '11 at 9:17

This question covers exactly the same content as earlier questions on this topic; its answers may be merged with another identical question. See the FAQ for guidance on how to improve it.

1 Answer

up vote 1 down vote accepted

I know php

Try This :

 function subval_sort($a,$subkey) {
foreach($a as $k=>$v) {
    $b[$k] = strtolower($v[$subkey]);
}
asort($b);
foreach($b as $key=>$val) {
    $c[] = $a[$key];
}
return $c;
 }

call to

 $songs = subval_sort($songs,'artist'); 
 print_r($songs);

If this answer is ok, pls accept my answer....

share|improve this answer
"I know php" - youtube.com/watch?v=EmEPXXJ4sKw ;-) – VolkerK Aug 4 '11 at 9:18
feedback

Not the answer you're looking for? Browse other questions tagged or ask your own question.