Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Sortowanie tablicy wg własnego wzoru
netvalue
post
Post #1





Grupa: Zarejestrowani
Postów: 199
Pomógł: 2
Dołączył: 9.06.2008

Ostrzeżenie: (0%)
-----


Witam

  1.  
  2. array(1) { ["myarr"]=> array(5) {
  3. [0]=> array(5) { ["symbol"]=> string(6) "EUR" ["desc"]=> string(6) "da" }
  4. [1]=> array(5) { ["symbol"]=> string(6) "USD" ["desc"]=> string(6) "adad" }
  5. [2]=> array(5) { ["symbol"]=> string(6) "CHF" ["desc"]=> string(6) "das23" }
  6. [3]=> array(5) { ["symbol"]=> string(6) "GBP" ["desc"]=> string(6) "dd12" }
  7. [4]=> array(5) { ["symbol"]=> string(6) "NOR" ["desc"]=> string(6) "233" }
  8. }
  9. }
  10.  


potrzebuje posortować ja symbol ale w kolejności takiej:
NOR, USD, EUR, CHF , GBP

Próbowałem z usort ale w tym przypadku chyba sie nie przyda...
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
netvalue
post
Post #2





Grupa: Zarejestrowani
Postów: 199
Pomógł: 2
Dołączył: 9.06.2008

Ostrzeżenie: (0%)
-----


zrobiłem wiec funkcje do uasort($myarr , 'sort_myarr')

  1.  
  2. function sort_myarr($a, $b) {
  3.  
  4. static $sizes = array( 'NOR' => 0, 'USD' => 1, 'EUR' => 2, 'CHF' => 3, 'GBP' => 4);
  5.  
  6.  
  7. return $sizes[$a] - $sizes[$b];
  8. }


ale niestety nie sortuje
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 15.10.2025 - 22:01