|
From: "Christoph Boget" on 15 Oct 2007 15:44 If I have an array that looks like this: Array ( [Salary] => Array ( [0-50K] => Array ( [filterType] => range [fieldLabel] => 0-50K [fieldName] => SALARY [lowerValue] => 0 [upperValue] => 50 [inclusive] => LEFT ) [50-70K] => Array ( [filterType] => range [fieldLabel] => 50-70K [fieldName] => SALARY [lowerValue] => 50 [upperValue] => 70 [inclusive] => BOTH ) ) ) How can I access the key values? Individually, that is. What about the child array key/values? Individually, that is. In the template, I've tried: {$myArray[0]} {$myArray[0].filterType} {$myArray[0][0]} Nothing seems to work. I know how to iterate through the entire array and display the contents that way, but I don't know how to get the key/value of just one particular element (and/or any child arrays of that element). Any help would be greatly appreciated! thnx, Christoph
From: "Max Schwanekamp" on 15 Oct 2007 16:41 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. -- Max Schwanekamp NeptuneWebworks.com 541-517-9064 How can I access the key values? Individually, that is. What about the child array key/values? Individually, that is. In the template, I've tried: {$myArray[0]} {$myArray[0].filterType} {$myArray[0][0]} Nothing seems to work. I know how to iterate through the entire array and display the contents that way, but I don't know how to get the key/value of just one particular element (and/or any child arrays of that element). Any help would be greatly appreciated! thnx, Christoph
From: "Christoph Boget" on 15 Oct 2007 16:54 On 10/15/07, Max Schwanekamp <lists(a)neptunewebworks.com> 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
From: Monte Ohrt on 15 Oct 2007 17:28 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(a)neptunewebworks.com> 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 > >
From: Josh Trutwin on 15 Oct 2007 17:31 > * get the total count of the elements w/o having to iterate through > the array {$my_array|@count} > * be able to access the first or last element even if the keys > aren't numeric Not very efficient but could do: {foreach from=$my_array item=arr name=arr_loop} {if $smarty.foreach.arr_loop.first} do something for first only {/if} {/foreach} Josh
|
Next
|
Last
Pages: 1 2 Prev: Newline being inserted after plugin - [SOLVED] Next: problems after upgrading to php5 |