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

get index of returned array

 
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 -> Tips and Tricks
View previous topic :: View next topic  
Author Message
gaspo
Smarty n00b


Joined: 27 Apr 2010
Posts: 3

PostPosted: Mon Mar 07, 2011 8:37 am    Post subject: get index of returned array Reply with quote

Hi,

I have multi-dimensional array

Code:
[messages] => Array
        (
            [0] => Array
                (
                    [id] => 252
                    [user_id] => 1311666
                    [message] => fdgdsfg
                )

            [1] => Array
                (
                    [id] => 223
                    [user_id] => 1311666
                    [message] => asdfasff
                )
        )


Is there any easy way how to get id of last message?

something like {$messages|@end .id}

{$messages|@end} whis returns array of last message, and I need the ID.

Thank you for any ideas.
Back to top
View user's profile Send private message
douglassdavis
Smarty Junkie


Joined: 21 Jan 2008
Posts: 541

PostPosted: Mon Mar 07, 2011 12:39 pm    Post subject: Re: get index of returned array Reply with quote

gaspo wrote:
Hi,

I have multi-dimensional array

Code:
[messages] => Array
        (
            [0] => Array
                (
                    [id] => 252
                    [user_id] => 1311666
                    [message] => fdgdsfg
                )

            [1] => Array
                (
                    [id] => 223
                    [user_id] => 1311666
                    [message] => asdfasff
                )
        )


Is there any easy way how to get id of last message?

something like {$messages|@end .id}

{$messages|@end} whis returns array of last message, and I need the ID.

Thank you for any ideas.




try
Code:

 {$messages|@array_keys|@array_pop}


in smarty 3 you don't need the @
Back to top
View user's profile Send private message
Eclypse
Smarty n00b


Joined: 19 Aug 2011
Posts: 1

PostPosted: Fri Aug 19, 2011 7:22 am    Post subject: Reply with quote

Yahoo! I have Smarty 3!
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 -> Tips and Tricks 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