PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > php.smarty.general > Counting number of array elements
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Counting number of array elements

Réponse
 
LinkBack Outils de la discussion
Vieux 09/02/2006, 15h15   #1
Dep
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Counting number of array elements

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
  Réponse avec citation
Vieux 09/02/2006, 15h16   #2
Monte Ohrt
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [SMARTY] Counting number of array elements

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
>
>
>

  Réponse avec citation
Vieux 09/02/2006, 15h42   #3
DC
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [SMARTY] Counting number of array elements

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
>>
>>
>>

>

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 19h59.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,07973 seconds with 11 queries