Re: [SMARTY] Multidimentional array loop.
| From: | Monte Ohrt | Date: | Tue, 19 Nov 2002 17:20:19 +0000 |
| Subject: | Re: [SMARTY] Multidimentional array loop. | ||
| References: | 1 2 3 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-6477@lists.php.net to get a copy of this message | ||
btw, there is also a timezone plugin in the repository you might want to
look at.
On Tue, 2002-11-19 at 11:08, Gerard Samuel wrote:
> Thanks for the advice. I could use this elsewhere also :).
> Unfortunately, I don't think it would work with my current example.
> The 2 arrays relate to each other, which {html_options} doesn't seem to
> provide for (I may be wrong).
> The only thing I can think of at the moment is to reconstruct a new flat
> array with the relationship intact,
> to feed to the template.
> Thanks once again...
>
> Monte Ohrt wrote:
>
> >Let {html_options} do this work for you. It's in the manual. ;-)
> >
> >Monte
> >
> >On Tue, 2002-11-19 at 10:14, Gerard Samuel wrote:
> >
> >
> >>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/
> >>
> >>
--
Monte Ohrt <monte@ispi.net>