Multidimentional array loop.
| From: | Gerard Samuel | Date: | Tue, 19 Nov 2002 16:14:31 +0000 |
| Subject: | Multidimentional array loop. | ||
| Groups: | php.smarty.general | ||
| Request: | Send a blank email to php-smarty-general+get-6474@lists.php.net to get a copy of this message | ||
Ive been trying to figure this out since last night. I have an array that is partly used for a <select> drop down list.
In PHP, I would loop throught the 'TZ' array for its key/value, and use the key to display the corresponding value in the 'offset' array like so ->
foreach($timezone['TZ'] as $k => $v)
{
echo '<option value="' . $timezone['offset'][$k] . '"';
if ($timezone['offset'][$k] == $user_tz)
{
echo ' selected';} echo '>' . $v . "\n"; } I tried using {foreach} in the template like -> {foreach key=key item=location from=$timezone.TZ} {if $timezone.offset.key == $user_tz}
<option value="{$timezone.offset.key}" selected>{$location}
{else}
<option value="{$timezone.offset.key}">{$location}
{/foreach}
But, Im unable to get {$timezone.offset.key} to return anything. Reading up in the documentation states, that {foreach} can only be used for one array. Im not sure if this rule was broken because, Im looping through one array and returning a value of another in my attempt.
Im currently reading up on {section}, but Im not too familiar with its usage, and Im trying a few things.
Could anyone point me as to how, one can handle this in template logic?
Thanks for any insight you may provide...
Snippet of array ->
array(2) {
["TZ"]=> array(33) { ["-12:00"]=> string(40) "(GMT-12:00) International Date Line West" ["-11:00"]=> string(32) "(GMT-11:00) Midway Island, Samoa" ["-10:00"]=> string(18) "(GMT-10:00) Hawaii" ["-09:00"]=> string(18) "(GMT-09:00) Alaska" ["-08:00"]=> string(47) "(GMT-08:00) Pacific Time (US & Canada), Tijuana" ["-07:00"]=> string(77) "(GMT-07:00) Arizona, Chihuahua, La Paz, Mazatlan, Mountain Time (US & Canada)" ["-06:00"]=> string(82) "(GMT-06:00) Central America, Central Time (US & Canada), Mexico City, Saskatchewan" ["-05:00"]=> string(75) "(GMT-05:00) Bogota, Lima, Quito, Eastern Time (US & Canada), Indiana (East)"}
["offset"]=> array(32) { ["-12:00"]=> string(3) "-12" ["-11:00"]=> string(3) "-11" ["-10:00"]=> string(3) "-10" ["-09:00"]=> string(2) "-9" ["-08:00"]=> string(2) "-8" ["-07:00"]=> string(2) "-7" ["-06:00"]=> string(2) "-6" ["-05:00"]=> string(2) "-5"} }
--
Gerard Samuel
http://www.trini0.org:81/
http://dev.trini0.org:81/