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

in operator missing?

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


Joined: 09 Mar 2005
Posts: 4

PostPosted: Wed Mar 09, 2005 9:17 pm    Post subject: in operator missing? Reply with quote

hi!

as far as i know, there's no "in" operator like "if $val in ('dog','cat','bla')".

if not, why not and could it be added? should be relatively simple i think, just map it to in_array or so.

gucki
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Wed Mar 09, 2005 9:24 pm    Post subject: Reply with quote

Good news: like all PHP functions, in_array can be used as a modifier so long as you aren't using secure mode. The only problem: you need to have your array predefined or you need a method to create an array from within the template if that is how you intend to do it.

{$needle|in_array:$haystack}
Back to top
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Wed Mar 09, 2005 9:39 pm    Post subject: Reply with quote

or {if in_array($needle, $haystack)} ... {/if} Smile
Back to top
View user's profile Send private message Send e-mail Visit poster's website
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Wed Mar 09, 2005 11:10 pm    Post subject: Reply with quote

**smacks head**

yes, that's a way better example since it shows its more likely usage Smile
Back to top
View user's profile Send private message
gucki
Smarty n00b


Joined: 09 Mar 2005
Posts: 4

PostPosted: Thu Mar 10, 2005 8:22 am    Post subject: Reply with quote

hey,

thanks so far. these methods i knew already, but i think it should be made simpler by adding an "in" operator, don't you think? wouldn't it be cool to have such a wonderful operator in smarty which also php misses? *G*

gucki
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