Re: [SMARTY] Array keys, values
[email protected] (Monte Ohrt) Mon, 15 Oct 2007 16:28:09 -0500
| Newsgroups | php.smarty.general |
|---|---|
| Message-ID | <[email protected]> |
You can get the count of an array with {$array|@count}
But, you are better off assigning the count if you need it, and also
assigning your keys/index values that make things as simple as possible
in the template. Instead of assuming the template should be able to
traverse your data in any format, instead format your data in a way that
is a easy as possible to traverse and display.
Christoph Boget wrote:
> On 10/15/07, Max Schwanekamp <[email protected]> wrote:
>
>> Christoph Boget wrote:
>>
>>> If I have an array that looks like this:
>>> Array ([Salary] => Array ( [0-50K] => Array ( [filterType] => range ) ) )
>>>
>>> How can I access the key values? Individually, that is. What about the
>>> child array key/values? Individually, that is.
>>>
>> {$myArray.Salary.0-50K.filterType} should work, but the key 0-50K might be
>> problematic due to the leading numeric character (I haven't tried it). If
>> it doesn't work, try adding a leading alpha char to those key names.
>>
>
>
> And if I don't know the key value off hand because the array was generated
> dynamically?
>
> As an aside, 2 features that would be really nice when working with arrays
> in a smarty template:
>
> * get the total count of the elements w/o having to iterate through the
> array
> * be able to access the first or last element even if the keys aren't
> numeric
>
> thnx,
> Christoph
>
>