Question: I am trying to check checkboxes based on values in a smarty array. 

In my php

```
$smarty->assign('locations_array',array(4,6,9,7));

```

I want to search through the array and if there is a match check the checkbox. 
Here is what I have tried in my template but I can't get it to work.I'm not sure how I can pass array\_search the needle and haystack that it requires?

```
{foreach $locations as $x}
   {if $x.id == $x.id|@array_search:$locations_array}
   <label><input checked type="checkbox" name="locations[]" value="{$x.id}"/>{$x.title}</label>
   {else}
     <label><input type="checkbox" name="locations[]" value="{$x.id}" />{$x.title</label>
   {/if}
{/foreach}

```

Is this possible without creating a custom function?

Answer: 
Without actually answering your main question (I don't know whether you can pass two vars to the function from the template), this could all be avoided by making a new array instead of `$locations` in the php file. Just looking at your posted code, you would want each element to have three sub-elements: `title`, `id`, and `checked`. This way you can avoid having to compare across arrays in the template side, and you can also avoid having to write a custom function.
i didnt works with array\_search but i have some simply solution for your issue.
you can check your checkbox value with the locations\_array in the foreach loop.

```
 **$i = 0;**
        {foreach $locations as $x}
           **{if $x.id == $locations_array[$i]}**
           <label><input checked type="checkbox" name="locations[]" value="{$x.id}"/>{$x.title}</label>
           {else}
             <label><input type="checkbox" name="locations[]" value="{$x.id}" />{$x.title</label>
           {/if}
**$i++;**
        {/foreach}

```