|modulo

The |modulo{xx} filter is a mathematical operation filter.
It returns the remainder of dividing the value of the tag by the value of xx.

  • New in : SPIP 1.9

|modulo{x} therefore always returns an integer between 0 and its first parameter "x" minus 1.

Example :
To change a display in a loop at each loop turn :

[(#COMPTEUR_BOUCLE|modulo{3})]

...will display "1" for the first result returned by the loop, then "2" for the second result, "0" for the third, then return to "1" for the fourth, "2" for the fifth...

2nd parameter

This filter accepts a second argument which must be numeric (either a whole number or floating point number) and which will be added to the result:

[(#VAL{20}|modulo{3, 2.4})]

will return "4.4".

Caution :
If the return of the tag is not of numeric type, it is considered as 0 (zero) and the filter returns 0 (zero).

[(#VAL{abcd}|modulo{8})]

... will return "0"

Example:
to make a display vary in a loop on each loop iteration:[(#COMPTEUR_BOUCLE|modulo{3})] will display "1"for the first record returned by the loop, then "2" for the second record, "0" for the third, then back to "1" for the fourth, "2" for the fifth, etc.

|modulo{x} therefore always returns an integer value between 0 and the value of its first argument less 1.

warning:
if 0 (zero) is passed as the argument to the filter ([(#VAL{20}|modulo{0})] for example), a PHP warning will be displayed: —Warning: Division by zero—.

See also

la balise

le filtre

Other mathematical operation filters:

Author Mark Published : Updated : 03/01/23

Translations : català, English, Español, français, Nederlands