Skip to content

02.26 Aggregate functions

rafageist edited this page Nov 16, 2026 · 1 revision

2.26 Funciones de agregación

Las funciones de agregación operan sobre listas y devuelven valores de resumen, de forma parecida a las funciones de agregación de SQL.

Sintaxis

{$function:variable-property}
Función de agregación Sintaxis para lista de listas/objetos Sintaxis para array de valores atómicos Descripción
min {$min:list-property} {$min:arrayname} Mínimo de la propiedad
max {$max:list-property} {$max:arrayname} Máximo de la propiedad
sum {$sum:list-property} {$sum:arrayname} Suma de las propiedades
avg {$avg:list-property} {$avg:arrayname} Promedio de las propiedades
count {$list-property} {$arrayname} Cantidad de propiedades verdaderas

Ejemplo

index.php

<?php

echo new div('index.tpl', [
    'blocks' => [
        ['title' => 'Who is online', 'weight' => 0, 'show' => true],
        ['title' => 'Last comments', 'weight' => 1, 'show' => false],
        ['title' => 'Forum topics', 'weight' => 2, 'show' => true]
    ],
    'widths' => [800, 700, 600, 500]
]);

index.tpl

<!--{ array of array/object }-->

Minimum weight: {$min:blocks-weight}
Maximum weight: {$max:blocks-weight}
Weight average: {$avg:blocks-weight}
Weight sum: {$sum:blocks-weight}
Showed blocks: {$blocks-weight} or {$count:blocks-weight}

<!--{ array of atomic values }-->

Minimum weight: {$min:widths}
Maximum weight: {$max:widths}
Weight average: {$avg:widths}
Weight sum: {$sum:widths}
Showed blocks: {$widths}

Salida

Minimum weight: 0
Maximum weight: 2
Weight average: 1
Weight sum: 3
Showed blocks: 2 or 2

Minimum weight: 500
Maximum weight: 800
Weight average: 650
Weight sum: 2600
Showed blocks: 4

Div

Enlaces

Clone this wiki locally