Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Multidimensionale Arrays ausgeben

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: German
View previous topic :: View next topic  
Author Message
raaa
Smarty n00b


Joined: 11 Oct 2004
Posts: 2

PostPosted: Mon Oct 11, 2004 3:46 pm    Post subject: Multidimensionale Arrays ausgeben Reply with quote

Hallo ich suche eine sinnvolle Möglichkeit mittels Schleifen ein mehrdimensionales Array mit Smarty auszugeben.
Wenn ein solches Array :

$test_array =array(
0 => array ("test0" => "0", "test1" => "1"),
1 => array ("test0" => "0", "test1" => "1")
);

so an Smarty übergebe

$smarty->assign("test_array", $test_array);

und dann so alle Werte ausgeben will:

{section name=xxx loop=$test_array}
ausgabe: {$test_array[xxx]}<br>
{/section}

bekomme ich nur den letzten im Array gespeicherten Wert.
Zwei foreach-Schleifen

{foreach name=outer from=$test_array item=level_one}
{foreach from=$level_one item=level_two}
question: {$level_two}<br>
{/foreach}
{/foreach}

geben gleich wieder alle Werte aus.
Alle ähnlichen Fragen in FAQ und im Forum liefen immer auf
das direkte ansprechen der Arrayelemente hinaus.
Gibt es eine Möglichkeit den numerischen Index mit einer Schleifenkonstruktion anzusprechen.
Back to top
View user's profile Send private message
raaa
Smarty n00b


Joined: 11 Oct 2004
Posts: 2

PostPosted: Mon Oct 11, 2004 4:16 pm    Post subject: Reply with quote

Ich habe selber eine Lösung gefunden die ich aber als
nicht sonderlich gelungen betrachte.

{foreach from=$test_array item=level_one}
{foreach from=$level_one.test0 item=item }
item: {$item}<br>
{/foreach}
{/foreach}

In der zweiten inneren Schleife lassen sich assoziative
Elemente direkt ansprechen

$level_one.test0 zeigt auf das erste Arrayelement

allerdings klärt das immer
noch nicht wie numerisch indizierte Elemente ansprechbar
sind. Dieses Vorgehen ist auch nur bei Datenbank-
abfragen oder ähnlichen Vorgängen bei denen feststehende
Arrayelementnamen erzeugt werden sinnvoll.
Back to top
View user's profile Send private message
McSodbrenner
Smarty Pro


Joined: 19 Sep 2004
Posts: 101
Location: Hamburg, Germany

PostPosted: Wed Oct 13, 2004 8:22 am    Post subject: Reply with quote

Ich weiß jetzt nicht, ob ichs genau verstanden habe, was du wilst, aber numerische Arrays kannste genauso ansprechen wie assoziative:

{$test_array.0.test0}
_________________
Grüzi, Smile
Christoph

My sweet home: www.webboarder.de
Do not visit!! It is private!! And it's mine!
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: German All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP