Re: [SMARTY] looping through variable names
| From: | Maximillian Schwanekamp | Date: | Wed, 17 Aug 2005 22:36:08 +0000 |
| Subject: | Re: [SMARTY] looping through variable names | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-12971@lists.php.net to get a copy of this message | ||
Kathleen Krause-Thomson wrote:
...I need to loop through array variable names as if they were variable variables. How would I do this in Smarty? <p>Job Title: {$budget1.jobTitle} Percent of Full Time:{$budget1.percentFullTime}</p> Next section needs to be:...From what you gave so far, it seems like you just need to assign your array $budget, and use {foreach} to iterate over it. E.g.: <?php $budgets = array(); $budgets[] = array('jobTitle'=>'First Job', 'percentFullTime'=>100); $budgets[] = array('jobTitle'=>'Second Job', 'percentFullTime'=>75); //etc... ?> {* smarty *} {foreach from=$budgets item="budget"} <p>Job Title: {$budget.jobTitle} Percent of Full Time:{$budget.percentFullTime}</p> {foreachelse} <p>No budgets found.</p> {/foreach} If that doesn't answer the question, can you post your PHP, and [a sample of] the array structure? -- Max Schwanekamp http://www.neptunewebworks.com/