title: Get first Smarty Array-Element
body: <p>How can i get the first smarty array element ?</p>
  
  <p>Actually i know how to do this... but i have following issue.</p>
  
  <p>I get a array passed that looks like this</p>
  
  <pre><code>[DATA] =&gt; Array
          (
              [12] =&gt; Array
                  (
                      [content] =&gt; foobar
                  )
  
              [1] =&gt; Array
                  (
                      [content] =&gt;  
                  )
  
              [2] =&gt; Array
                  (
                      [content] =&gt;  
                  )
  
              [3] =&gt; Array
                  (
                      [content] =&gt;  
                  )
  
   //this is a snipit of {$myVar|@print_r}
  </code></pre>
  
  <p>this goes down until <code>[11]</code></p>
  
  <p>For some reason there is no <code>[0]</code> and a <code>[12]</code> at this position.</p>
  
  <p>I don't know if this will allways be 12 but I know it allways be at the first position.</p>
  
  <p>I can't sort this array because there is another array that has the same sortorder and I have to keep this order for later output.</p>
  
  <p>Is there a way to select the first element without using <code>array[0]</code> or <code>array.0</code> ?</p>
  
  <p><i><strong>Info:</strong> The project im working on uses Smarty 2</i></p>
  
  <p><strong>EDIT</strong></p>
  
  <blockquote>
    <ul>
    <li>I would re-index the array if i knew how :)</li>
    </ul>
  </blockquote>
  
  <h3>Since there is now answere after a couple of hours, i solved my problem temporarly.</h3>
  
  <p>To solve this, I opened <code>{php}</code> in smarty, got the array I need, splitted it into two arrays (re-indexing them of course so it starts at <code>0</code>). Than I temp-save pos <code>0</code>  from each array to a temp array. Override the orig <code>0</code> with underscore (_) and than multisort them, put back the original value to <code>0</code> and pass them back to <code>$this-&gt;_tpl_vars</code> very complicated way. (all inside the tpl)</p>
  
  <pre><code>{php}
      // get array data and re-index it
      $i=0;
      foreach( $this-&gt;_tpl_vars['options'] as $option )
      {
          foreach( $option['DATA'] as $data )
              $array[$i][] = $data;
          $i++;
      }
  
      //delete empty entrys
      $i=0;
      foreach( $array[1] as $data ){
          if(trim($data['content']) != ""){
              $s[] = $array[0][$i];
              $a[] = $array[1][$i];
          }
          $i++;
      }
  
      //temp save first values
      $tmp_s  = $s[0];
      $tmp_a  = $a[0];
  
      //override first values to have a clean sort and keep them values on pos 0
      $s[0] = $a[0] = "_";
  
      //sort the arrays
      array_multisort($s,$a);
  
      //putting back the original values
      $s[0] = $tmp_s;
      $a[0] = $tmp_a;
  
      //pass the array back to tpl_vars
      $this-&gt;_tpl_vars['new_options'][] = $s;
      $this-&gt;_tpl_vars['new_options'][] = $a;
  
  
  {/php}
  </code></pre>