title: Assign Variable Within Foreach Loop
body: <p>I am fetching an array and I would like to assign attributes of items within the array to individual variables. For example, I want to assign a variable named user_1_name to include userInfo.name from the first userID and user_2_name to include userInfo.name from the second userID. Here is the code as it stands now, it uses a proprietary method named 'get_friend_list':</p>
  
  <pre><code>{assign var="friend_list" value=""}
  {get_friend_list snid=$TOSNID snuid=$TOUID gameid=$GAMEID assign="friend_list"}
  {if $friend_list|@count &gt; 0}
    {foreach from=$friend_list key=userId item=userInfo name=friend_list}
      {if $smarty.foreach.friend_list.index &lt; 4 &amp;&amp; $smarty.foreach.friend_list.index &gt;= 0 &amp;&amp; !empty($userInfo.user_uid) }                             
        ***VARIABLE ASSIGNMENT HERE***
      {/if}
    {/foreach}
  {else}
  {/if}
  </code></pre>
  
  <p>If this is an unclear question, let me know and I will attempt to clear it up.</p>
  
  <p>Thanks</p>
  
  <p>EDIT: BTW, if you didn't notice, I am using Smarty.</p>