logo       

[SMARTY] foreach and multidimensional arrays: msg#00376

php.smarty.general

Subject: [SMARTY] foreach and multidimensional arrays

H'lo folks...

Apologies if this has been covered earlier, I had no luck searching for it... although it could be I'm not phrasing things correctly.

I have a multidimensional array that looks basically like this:
$foo = array(
bar => array (
a => array ( 'dog' , 'cat' , 'etc' )
)
)

The template I'm trying to jam this structure into looks something like this:
{ foreach key=type from=$foo item=pulldowns }
...snip some html here...
{ foreach key=pulldown from=$pulldowns item=values }
<select name="blah">
<option> any { $pulldown }</option>
{ html_options options=$values }
</select>
{ /foreach }
{ /foreach }

Net result is supposed to be a set of pulldowns ('a', with values of 'dog' , 'cat' , 'etc') for each of the supplied types ('bar'). What's happening is that the values of the last array, the non-associative one, are being output twice... once with keys of [ 0 ... n ] and then again with the value of $pulldown. Although unexpected, I understand why the "extra" values are showing up... but my perl background is a source of continual surprise when I'm working with what I think of as hashes.

Short version... how do I suppress the values that are due to the numeric keys? Or, for bonus points, vice versa? ;)

Appreciate any direction/input you can provide...


--
Smarty General Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise