Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php] jak ustawic tablice od najwiekszej wartosci
AndyPSV
post
Post #1





Grupa: Zarejestrowani
Postów: 393
Pomógł: 5
Dołączył: 6.02.2003
Skąd: The.Luciferian.Doctrine.p
df

Ostrzeżenie: (30%)
XX---


Mam takie cos, chce ustawic ta tablice po najwiekszej wartosci "e_months0" (teraz jest dobrze ustawiona, ale jak zrobic skrypt, ktory by ustawial ja?):

  1. 0 =>
  2. 'id' => '1',
  3. 'nick' => 'AndyPSV',
  4. 'status' => 'admin',
  5. 'first_name' => 'Andrzej Jeziorski',
  6. 'c_months3' => 0,
  7. 'c_months1' => 0,
  8. 'c_months0' => 5,
  9. 'c_months_now' => 3,
  10. 'e_months3' => '',
  11. 'e_months1' => '',
  12. 'e_months0' => '100',
  13. 'this_month' => 500,
  14. ),
  15. 1 =>
  16. 'id' => '2',
  17. 'nick' => 'Toruniak',
  18. 'status' => 'caller',
  19. 'first_name' => '',
  20. 'c_months3' => 0,
  21. 'c_months1' => 0,
  22. 'c_months0' => 0,
  23. 'c_months_now' => 0,
  24. 'e_months3' => '',
  25. 'e_months1' => '',
  26. 'e_months0' => '',
  27. 'this_month' => 0,
  28. ),
  29. )
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
AndyPSV
post
Post #2





Grupa: Zarejestrowani
Postów: 393
Pomógł: 5
Dołączył: 6.02.2003
Skąd: The.Luciferian.Doctrine.p
df

Ostrzeżenie: (30%)
XX---


Wynik, nie dziala - moze cos robie zle?

  1. $array[0]: 100 $array[1]: 400 $array[2]: 50


a ma byc tak:
  1. $array[0]: 400 $array[1]: 100 $array[2]: 50



  1. <?php
  2. function cmp($a, $b)
  3. {
  4. return strcmp($a["e_months0"], $b["e_months0"]);
  5. }
  6.  
  7. $array = array (
  8. 0 =>
  9. 'id' => '1',
  10. 'nick' => 'AndyPSV',
  11. 'status' => 'admin',
  12. 'first_name' => 'Andrzej Jeziorski',
  13. 'c_months3' => 0,
  14. 'c_months1' => 0,
  15. 'c_months0' => 5,
  16. 'c_months_now' => 3,
  17. 'e_months3' => '',
  18. 'e_months1' => '',
  19. 'e_months0' => '100',
  20. 'this_month' => 500,
  21. ),
  22. 1 =>
  23. 'id' => '2',
  24. 'nick' => 'Toruniak',
  25. 'status' => 'caller',
  26. 'first_name' => '',
  27. 'c_months3' => 0,
  28. 'c_months1' => 0,
  29. 'c_months0' => 0,
  30. 'c_months_now' => 0,
  31. 'e_months3' => '',
  32. 'e_months1' => '',
  33. 'e_months0' => '50',
  34. 'this_month' => 0,
  35. ),
  36. 2 =>
  37. 'id' => '2',
  38. 'nick' => 'Toruniak',
  39. 'status' => 'caller',
  40. 'first_name' => '',
  41. 'c_months3' => 0,
  42. 'c_months1' => 0,
  43. 'c_months0' => 0,
  44. 'c_months_now' => 0,
  45. 'e_months3' => '',
  46. 'e_months1' => '',
  47. 'e_months0' => '400',
  48. 'this_month' => 0,
  49. ),
  50. );
  51.  
  52. usort($array, "cmp");
  53.  
  54. while (list($key, $value) = each($array)) {
  55. echo "\$array[$key]: " . $value["e_months0"] . "\n";
  56. }
  57.  
  58. ?>


Ten post edytował AndyPSV 11.09.2010, 16:35:37
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: 16.10.2025 - 00:39