title: Smarty: check if variable is in array
body: <p>I'm using php with smarty.  In php I have two arrays:</p>
  
  <pre><code>$code = Array
  (
      [n_id] =&gt; 1
      [t_code] =&gt; ABC123
      [t_description] =&gt; Test code
      [b_enabled] =&gt; Yes
      [n_type] =&gt; 3
      [dt_start] =&gt; 
      [dt_end] =&gt; 
      [n_min_req_gbp] =&gt; 0
      [n_min_req_usd] =&gt; 0
      [n_amount_gbp] =&gt; 
      [n_amount_usd] =&gt; 
      [n_max_overall_gbp] =&gt; 
      [n_max_overall_usd] =&gt; 
      [n_extra] =&gt; 6
      [b_reuse] =&gt; No
      [n_applications] =&gt; Array
          (
              [0] =&gt; 2
          )
  )
  </code></pre>
  
  <p>and</p>
  
  <pre><code>$all_application = Array
  (
      [1] =&gt; New registration
      [2] =&gt; Mid-subscription upgrade
      [3] =&gt; Subscription renewal
      [4] =&gt; Additional purchase
  )
  </code></pre>
  
  <p>Note that the second array may - and will - grow, this is the reference data, from which <code>n_applications</code> array field in the first array is built.  That is, the array in <code>n_applications</code> will contain a subset of keys from the <code>$all_applications</code> arrays.</p>
  
  <p>Now, I'm assigning these two arrays into the template:</p>
  
  <pre><code>$template-&gt;assign('code', $code);
  $template-&gt;assign('apps', $all_applications);
  </code></pre>
  
  <p>And in the template, I'm creating a form for editing the fields in the <code>$code</code> array.  Everything is working fine except the 'applications' selection.  I want to pre-select those apps that are already in the <code>n_applications</code> field.  So, in my template I have this:</p>
  
  <pre><code>&lt;select name="c_apps[]" size="3" class="multiselect" multiple="multiple"&gt;
      {foreach from=$apps key=k item=a}
          {assign var=v value=$k|@array_search:$code['n_applications']}
          &lt;option value="{$k}"{if $v!==FALSE} selected="selected"{/if}&gt;{$a|escape}&lt;/option&gt;
      {/foreach}
  &lt;/select&gt;
  </code></pre>
  
  <p>However this doesn't work as expected - and ALL options end up being selected.  I tried using <code>in_array</code> function - but with the same result.  What's the best way to achieve what I'm after?</p>