title: How to access key and value of an array in smarty template?
body: <p>I'm assigning an array named <code>$enquiries_labels</code> <strong>from php file to a smarty template file</strong>. If I print the array in PHP file it's output is as follows:</p>
  
  <pre><code>Array
  (
      [0] =&gt; New Enquiry
      [1] =&gt; Retail Enquiry
      [2] =&gt; Feedback
      [3] =&gt; Payment Query
      [4] =&gt; Package Query
      [5] =&gt; Test Query
  )
  </code></pre>
  
  <p>Now after assigning this array to a smarty file I want to access these values in a select HTML control. For it I need to use foreach loop construct of smarty template engine. If a pre-selected value is matching with the key from array then I'll keep that value selected. For achieving this I tried below code, but it didn't work for me. Can anyone help me in this regard please? For your reference I'm putting below the code I tried in smarty template:</p>
  
  <pre><code>&lt;select name="contact_label" id="contact_label"&gt; 
  {if $enquiries_labels}
                    {foreach from=$enquiries_labels item=label}
                      &lt;option value="{$label.key}" {if $data.key == $label.key} selected="selected" {/if}&gt;{$label.value}
                      &lt;/option&gt;
                    {/foreach}
                  {/if}
        &lt;/select&gt;
  </code></pre>
  
  <p>Thanks for spending some of your valuable time in understanding my issue. </p>