foreach and multidimensional arrays
| From: | m guckeyson | Date: | Mon, 27 Jan 2003 21:20:11 +0000 |
| Subject: | foreach and multidimensional arrays | ||
| Groups: | php.smarty.general | ||
| Request: | Send a blank email to php-smarty-general+get-7351@lists.php.net to get a copy of this message | ||
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...