Re: [SMARTY] question

From: Date: Thu, 03 Apr 2003 22:37:54 +0000
Subject: Re: [SMARTY] question
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-9064@lists.php.net to get a copy of this message
On Thu, Apr 03, 2003 at 04:54:07PM -0500, Super Gabey wrote: > > can you loop through an array if its index is other than numerical? > > foo.php > $logdata->results[0]['date']="date"; > $logdata->results[0]['policy']="policy"; > $logdata->results[0]['action']="action"; > $logdata->results[1]['date']="ag"; > $logdata->results[1]['policy']="pol"; > $logdata->results[1]['action']="dance"; > > > foo.tpl > {section name=logrowloop loop=$logdata->results[0]} > {$logdata->results[0][logrowloop]} > {/section} > > > > It appears as if this won't work - but I'd really like to be wrong :( you a wrong. :) you want to do {foreach from=$logdata->results.0 key=name item=value} $value {/foreach} ({foreach} can loop over arbitrary array, {section} only over indexed ones) of course you dont need "key" in this example, since it isn't use, but you have access 'date', 'policy', 'action' ... if you need you could also write "$logdata->results.0.$key" instead of "$value", but "$value" is simpler, better faster. HTH messju

« previous php.smarty.general (#9064) next »