Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP]Wyciąganie danych z tablicy
Forum PHP.pl > Forum > Przedszkole
Wykrywacz
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 ?
piotrooo89
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
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.