|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Hello to all!
Is there any straight and obvious way to count the number of elements in some array??? maybe I'm blind, but can't find that in the manual, and the only way out I've found so far is like this. {foreach from=$some_arr item=$i name="my_foreach"}{/foreach} Number of elements: {$smarty.foreach.my_foreach.total} Looks horribly stupid So, any other way?Best regards Dmitriy |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
http://smarty.incutio.com/?page=Smar...ons#template-1
Dep wrote: >Hello to all! > >Is there any straight and obvious way to count the number of elements >in some array??? > >maybe I'm blind, but can't find that in the manual, and the only way >out I've found so far is like this. > >{foreach from=$some_arr item=$i name="my_foreach"}{/foreach} >Number of elements: {$smarty.foreach.my_foreach.total} > >Looks horribly stupid So, any other way?> >Best regards >Dmitriy > > > |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
That FAQ page Monte Ohrt sent has lots of useful info.
Remember, any PHP function can be used in a smarty template. The simple array functions are handy in a pinch. {$array|@count} {$array|@min} {$array|@max} {$array|@array_sum} the order is weird for functions that expect multiple params especially the needle, haystack array functions. you have to send the needle and then put the array as the param to the function like so: {$value|@in_array:$array} some functions just don't make any sense for use in the templates. dc Q: How do I count the number of elements in an array? A: {$array|@count} The "@" applies the modifier directly to the array instead of each individual element. Monte Ohrt had written: > http://smarty.incutio.com/?page=Smar...ons#template-1 > > Dep wrote: > >> Hello to all! >> >> Is there any straight and obvious way to count the number of elements >> in some array??? >> >> maybe I'm blind, but can't find that in the manual, and the only way >> out I've found so far is like this. >> >> {foreach from=$some_arr item=$i name="my_foreach"}{/foreach} >> Number of elements: {$smarty.foreach.my_foreach.total} >> >> Looks horribly stupid So, any other way?>> >> Best regards >> Dmitriy >> >> >> > |
|
![]() |
| Outils de la discussion | |
|
|