Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Problem z foreach
ladovnik
post
Post #1





Grupa: Zarejestrowani
Postów: 60
Pomógł: 1
Dołączył: 25.11.2008
Skąd: Polska

Ostrzeżenie: (10%)
X----


Witam. Mam pewien problem z foreach. Napisałem taki oto kod:

  1. <?php foreach(getSongs() as $data): ?>
  2. <tr>
  3. <td><strong><?php songId(); ?></strong></td>
  4. <td><strong><?php songName(); ?></strong></td>
  5. <td><strong><?php songFile(); ?></strong></td>
  6. <td><strong><?php songSize(); ?></strong></td>
  7. </tr>
  8. <?php endforeach; ?>


Funkcja songId() to:
  1. function songId() {
  2. global $data;
  3. echo $data['s_id'];
  4. }


Niestety, w/w funkcja nie widzi zmiennej $data, podobnie jak pozostałe. Czy wie ktoś, co z tym zrobić?

Pozdrawiam,
ladovnik

Ten post edytował ladovnik 13.02.2011, 13:15:29
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Zbigizmi
post
Post #2





Grupa: Zarejestrowani
Postów: 18
Pomógł: 4
Dołączył: 4.02.2011

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


A co robi funkcja getSongs()?

Nie może widzieć zmiennej $data ponieważ deklaracja o global znajduje się wewnątrz funkcji
a tam już jej niem.
Zrób
  1.  
  2.  
  3. <?php foreach(getSongs() as $data): ?>
  4.  
  5. <tr>
  6.  
  7. <td><strong><?php songId($data); ?></strong></td>
  8.  
  9. <td><strong><?php songName($data); ?></strong></td>
  10.  
  11. <td><strong><?php songFile($data); ?></strong></td>
  12.  
  13. <td><strong><?php songSize($data); ?></strong></td>
  14.  
  15. </tr>
  16.  
  17. <?php endforeach; ?>
  18.  
  19.  
  20.  
  21. function songId($data) {
  22.  
  23. echo $data['s_id'];
  24.  
  25. }
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: 5.10.2025 - 11:27