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

X Element aus foreach array anzeigen

 
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
bamsi
Smarty n00b


Joined: 01 Jul 2017
Posts: 3

PostPosted: Sat Jul 01, 2017 4:19 pm    Post subject: X Element aus foreach array anzeigen Reply with quote

Hallo,

Wie kann ich aus einer foreach schleife nur ein X beliebiges element anzeigen?
Beispiel wenn ich den vorletzten Element anzeigen möchte?

Der Array:
Code:
Array
(
    [0] => stdClass Object
        (
            [name] => first
        )

    [1] => stdClass Object
        (
            [name] => second
        )

    [2] => stdClass Object
        (
            [name] => third
        )
)


Mein foreach code:

Code:
{foreach $oItem as $oItems}
    {if $oItem@last}
        {$oItem->name|count -1}
    {/if}
{/foreach}
Back to top
View user's profile Send private message
elpmis
Smarty Elite


Joined: 07 Jun 2007
Posts: 321

PostPosted: Sat Jul 01, 2017 6:21 pm    Post subject: Reply with quote

Syntaxfehler?

Code:
{foreach $oItems as $oItem} 
Back to top
View user's profile Send private message
bamsi
Smarty n00b


Joined: 01 Jul 2017
Posts: 3

PostPosted: Sun Jul 02, 2017 9:07 am    Post subject: Reply with quote

Ja sorry, aber auch damit funktioniert es nicht Sad

Ausgabe ist dann 0, denke das der count den key zählt und einfach -1 macht. Aber ich möchte "name" anzeigen und nicht den wert
Back to top
View user's profile Send private message
bamsi
Smarty n00b


Joined: 01 Jul 2017
Posts: 3

PostPosted: Sun Jul 02, 2017 9:49 am    Post subject: Reply with quote

Hab die Lösung

{assign var=i_kat value=$oItem|@count}
{assign var=i_kat value=$i_kat-2}
{$oItem[$i_kat]->name}
Back to top
View user's profile Send private message
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