I am trying to write an if statement based on the variable that can be an array.
This variable outputs category ids that each product has.
I can display them all using:
{foreach from=$iCat item=cat}
{$cat.category_id}
{/foreach}
I want the if statement to be based on the category id.
{if $iCat contains(out of multiple numbers) 10}
Do something
The problem is that the variable returns multiple values and it doesn't work.
My Answer:
To check if the category id 10 is present in the array of category ids, you can use the in_array function in Smarty. Here's how you can modify your if statement:
smarty
{if in_array(10, $iCat)}
Do something
{/if}
This will check if the category id 10 is present in the array of category ids stored in the variable $iCat. If it is present, the code inside the if statement will be executed.
Rate this post
4 of 5 based on 5055 votesComments