Re: [SMARTY] Array keys, values
| From: | Monte Ohrt | Date: | Mon, 15 Oct 2007 21:28:09 +0000 |
| Subject: | Re: [SMARTY] Array keys, values | ||
| References: | 1 2 3 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-13780@lists.php.net to get a copy of this message | ||
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 <lists@neptunewebworks.com> wrote: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, ChristophChristoph Boget wrote:{$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.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.If I have an array that looks like this: