Re: [SMARTY] question

From: Date: Thu, 03 Apr 2003 22:52:28 +0000
Subject: Re: [SMARTY] question
References: 1 2  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-9066@lists.php.net to get a copy of this message
On Thu, Apr 03, 2003 at 10:37:54PM +0000, messju mohr wrote: > 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. sorry about the horrible speling. i've been a bit in a rush. i hope it's understandable with a bit of imagination :) > HTH > messju

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