Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Segregacja zarówno wedle nazw jak i liczb
Gigante
post
Post #1





Grupa: Zarejestrowani
Postów: 61
Pomógł: 0
Dołączył: 29.09.2006
Skąd: Oława

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


Mam prosta tabele:
  1. <?php
  2. function posegreguj($segregacja)
  3. {
  4. $segregacje = array (
  5. '--wybierz--',
  6. 'najstarsze',
  7. 'najnowsze',
  8. 'najlepsze',
  9. 'najgorsze',
  10. 'bez ocen'
  11. );
  12.  
  13. return $segregacje[$segregacja];
  14. }
  15. ?>


wywolujac np: posegreguj(2) dostaje pozycje najnowsze

wywolujac np: posegreguj(najlepsze) chce dostac ktore miejsce w tabeli zajmuje to slowo (czyli: sytuacja odwrotna)... jak ? Najlepiej bez tworzenia nowej tabeli (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)

Ten post edytował Gigante 30.07.2008, 07:39:55
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
kampio
post
Post #2





Grupa: Zarejestrowani
Postów: 15
Pomógł: 1
Dołączył: 22.07.2008

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


  1. <?php
  2. function posegreguj($segregacja)
  3. {
  4. $segregacje = array (
  5. '--wybierz--',
  6. 'najstarsze',
  7. 'najnowsze',
  8. 'najlepsze',
  9. 'najgorsze',
  10. 'bez ocen'
  11. );
  12.  
  13. if(is_int($segregacja)) return $segregacje[$segregacja];
  14. else return array_search($segregacja,$segregacje);
  15. }
  16. echo posegreguj(1);
  17. echo posegreguj("bez ocen");
  18. ?>
  19.  
  20. zamiast is_int mozna dac: if(ereg('^[0-9]+$',$segregacja)) return $segregacje[$segregacja];


Ten post edytował kampio 30.07.2008, 12:04:55
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: 4.10.2025 - 22:13