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

How can I know if an array contain a data

 
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 -> General
View previous topic :: View next topic  
Author Message
pierrot10
Smarty n00b


Joined: 08 Apr 2012
Posts: 4

PostPosted: Sun Apr 08, 2012 8:13 pm    Post subject: How can I know if an array contain a data Reply with quote

Dear All,
I ma new with smarty.

I have an array {$myarray} and I can not use a foreach like this
Code:
{foreach from=$myarray key=key item=myarrayItem name=myarrayName}
{/foreach}


I woule like to do as we do with php
Code:
in_array('toto', $myarray)


How can I do with smarty?
I need to get a true if my value is in the array and a false if not.

Many thank for your help
Back to top
View user's profile Send private message
kataxxx
Smarty Rookie


Joined: 08 Apr 2012
Posts: 10

PostPosted: Sun Apr 08, 2012 8:18 pm    Post subject: Reply with quote

Try
Code:
{if isset($myarrayItem.toto) }
  true
{else}
  false
{/else}

This should work.
Back to top
View user's profile Send private message
pierrot10
Smarty n00b


Joined: 08 Apr 2012
Posts: 4

PostPosted: Sun Apr 08, 2012 8:28 pm    Post subject: Reply with quote

No I found the solution:

Code:
{if in_array('toto', $db_id_productsPool)}
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 -> General 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