Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Wyświetlanie tablicy
aceide
post
Post #1





Grupa: Zarejestrowani
Postów: 65
Pomógł: 0
Dołączył: 13.05.2004
Skąd: Uć.

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


Mam tablicę:

  1. <?php
  2. $array = array(
  3.  
  4. &#092;"server\" => array(
  5.         &#092;"quota\" => array(\"element1\",\"element2\",\"element3\",\"element4\"),
  6.         &#092;"band\" => array(\"element5\",\"element6\",\"element7\",\"element8\")
  7.                    )
  8.         
  9. );
  10. ?>

... i chcę, aby za pomocą pętli wyświetlało mi zawartość całego $array["server"]. w postaci (na podstawie w/w przykładu):

element1,element2,element3,element4 <BR>
element5,element6,element7,element8 <BR>

Nie bardzo wiem jak to wyjaśnić.

Robiłem w ten sposób, ale nie działa:

  1. <?php
  2. while ($category = each ($array[&#092;"server\"]) )
  3. {
  4. echo $array[&#092;"server\"][$category][1].$array[\"server\"][$category][2].$array[\"server\"][$category][3].$array[\"server\"][$category][4];                
  5. }
  6. ?>


Help (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)

Ten post edytował aceide 15.07.2005, 15:34:52
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
kszychu
post
Post #2





Grupa: Przyjaciele php.pl
Postów: 2 712
Pomógł: 23
Dołączył: 27.10.2003
Skąd: z kontowni

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


@nospor, ja bym tam nie dawał drugiego foreach. Z tego co widzę, liczba elementów w podtablicy jest stała, więc:
  1. <?php
  2. foreach ($array['server'] as $ind => $tab)
  3. {
  4. echo &#092;"{$ind}:<b>{$tab[0]}</b> <i>{$tab[1]}</i> <u>{$tab[2]}</u> {$tab[3]}<br>\";
  5.  
  6. ?>
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: 6.10.2025 - 03:48