Re: [SMARTY] accessing values in multi-dimensional associative arrays
| From: | Mark Rogers | Date: | Sun, 01 May 2005 11:18:13 +0000 |
| Subject: | Re: [SMARTY] accessing values in multi-dimensional associative arrays | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-12561@lists.php.net to get a copy of this message | ||
Christopher Townson writes:
> == start code: my feeble attempt at looping though stylesheet values! ==
> {foreach from="$doc.stylesheets.css.linked" key="key"
> item="stylesheet"}
> <link rel="{$key.rel}" type="text/css" href="{$key.href}"
> charset="{$key.charset}" title="{$key.title}"
> media="{$key.media}" />
> {/foreach}
> == end code ==
Looking at your example, on the first iteration of the loop
$key = 'default';
$stylesheet = array(
'rel' => 'stylesheet',
'href' => 'stylesheet.css',
'charset' => 'iso-8859-1',
'title' => 'Default Stylesheet',
'media' => 'screen'
);
So your code would be fine if you swap {$key.rel} for {$stylesheet.rel} and
likewise for all other components.
Think of the equivalent PHP foreach code:
foreach($doc['stylesheets']['css']['linked'] as $key =>
$stylesheet) {
// use $stylesheet['rel'] (etc) here, not $key['rel'] which is
meaningless
}
Mark Rogers,
More Solutions Ltd