Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]Wyciąganie danych z tablicy
Wykrywacz
post
Post #1





Grupa: Zarejestrowani
Postów: 726
Pomógł: 20
Dołączył: 8.12.2005
Skąd: Wrocław

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


Mam sobie powiedźmy

  1. function tab5($a){
  2. ...
  3. $tab[1.22] = 0.8923;
  4. $tab[1.23] = 0.8993;
  5. ...
  6. return $tab[$a];
  7. }
  8.  
  9. $a = 1.22;
  10. $abrakadabra = obliczenia::tab5($a);

No i zwraca mi jakieś głupoty.

Jak bym zrobił

  1. function tab($a){
  2. ...
  3. $tab['1.22'] = 0.8923;
  4. $tab['1.23'] = 0.8993;
  5. ...
  6. return $tab[$a];
  7. }
  8. $a = '1.22';
  9. $abrakadabra = obliczenia::tab5($a);

To wszystko jest wporzo.
Czy możecie mi wyjaśnić czemu ten $tab nie może mieć floutowych liczb jako klucze ?

Ten post edytował Wykrywacz 2.11.2009, 12:11:04
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 1)
piotrooo89
post
Post #2


Newsman


Grupa: Moderatorzy
Postów: 4 005
Pomógł: 548
Dołączył: 7.04.2008
Skąd: Trzebinia/Kraków




prosze cytat z manuala:

Cytat
A key may be either an integer or a string. If a key is the standard representation of an integer, it will be interpreted as such (i.e. "8" will be interpreted as 8, while "08" will be interpreted as "08"). Floats in key are truncated to integer. The indexed and associative array types are the same type in PHP, which can both contain integer and string indices.


http://pl2.php.net/manual/pl/language.types.array.php
Go to the top of the page
+Quote Post

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: 5.10.2025 - 20:14