Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I was wondering how I could sort this array, when I use asort right now it does

14 17 16 15.

How would I go to have

14 15 16 17

  array(4) { 
        [15]=>  array(9) { 
         [2025]=>  string(80) "20:25 à 21:15 Spectacle / L'histoire d'un coeur / Auditorium, É.S.P. De La Salle" 
         [2135]=>  string(71) "21:35 à 22:25 Spectacle / Transfugue 2 / Auditorium, É.S.P. De La Salle" 
         [1430]=>  string(64) "14:30 à 15:30 Mise en lecture/Théâtre la Catapulte / De La Salle" 
         [110]=>  string(44) "11:00 à 13:00 Inscription / Pavillon Tabaret" 
         [1330]=>  string(49) "13:30 à 14:30 CÉRÉMONIE D'OUVERTURE / De La Salle" 
         [1550]=>  string(61) "15:50 à 16:40 Spectacle/Université Laurentienne / De La Salle" 
         [170]=>  string(57) "17:00 à 17:50 Spectacle/Université d'Ottawa / De La Salle" 
         [1750]=>  string(45) "17:50 à 19:00 REPAS DE L'AMITIÉ / De La Salle" 
         [1915]=>  string(76) "19:15 à 20:05 Spectacle / Attendre la pluie / Auditorium, É.S.P. De La Salle" } 
        [16]=>  array(8) { 
         [1845]=>  string(81) "18:45 à 19:35 Spectacle / Mimes d'horreur / Salle Académique, Université d'Ottawa" 
         [1955]=>  string(73) "19:55 à 20:45 Spectacle / Déroute / Salle Académique, Université d'Ottawa" 
         [8]=>  string(45) "08:30 à 11:30 Atelier / ABC du jeu dramatique" 
         [13]=>  string(41) "13:00 à 16:00 Atelier / Théâtre physique" 
         [1130]=>  string(28) "11:30 à 13:00 DÎNER LIBRE / " 
         [1620]=>  string(29) "16:20 à 18:20 SOUPER LIBRE / " 
         [220]=>  string(58) "22:00 à 23:30 BAL MASQUÉ / l'Agora du centre universitaire" 
         [210]=>  string(47) "21:00 à 22:00 Rétroaction / Université d'Ottawa" } 
        [17]=>  array(4) { 
         [950]=>  string(79) "09:50 à 10:40 Spectacle / Raison d'être / Salle Académique, Université d'Ottawa" 
         [110]=>  string(76) "11:00 à 11:50 Spectacle / Potionnée / Salle Académique, Université d'Ottawa" 
         [120]=>  string(28) "12:00 à 13:00 DÎNER LIBRE / " 
         [1330]=>  string(48) "13:30 à 14:30 CÉRÉMONIE DE CLÔTURE / De La Salle" } 
        [14]=>  array(1) { 
         [150]=>  string(49) "15:00 à 16:30 Préparation technique / De La Salle" } } 
share|improve this question

3 Answers

up vote 10 down vote accepted

You want ksort(), which will sort the array by key instead of value.

share|improve this answer
 
Good catch, I would have suggested the same :) –  Gazillion Apr 6 '10 at 18:42
 
Wow. Thanks gazillion –  Melonheadjr44 Apr 6 '10 at 18:47

You're looking for the sort by key function:

ksort()
share|improve this answer

I would check out http://us.php.net/manual/en/function.sort.php. There are some examples there of how how to implement the sort the way you want. Also if its sorted but you want the reverse order use array_reverse().

share|improve this answer
 
how about using the reverse of ksort or sort instead of array_reserve? like krsort or rsort respectively –  mauris Apr 6 '10 at 18:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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