Update reduce.rst

remove note, better argument for example
reduce doesn't use array_reduce anymore
https://github.com/twigphp/Twig/issues/3802
This commit is contained in:
AndCycle
2025-05-12 16:54:49 +08:00
committed by GitHub
parent 12a40e714c
commit bb6382c1bb
+2 -8
View File
@@ -10,14 +10,14 @@ value and key of the sequence or mapping:
{% set numbers = [1, 2, 3] %}
{{ numbers|reduce((carry, v, k) => carry + v * k) }}
{{ numbers|reduce((carry, value, key) => carry + value * key) }}
{# output 8 #}
The ``reduce`` filter takes an ``initial`` value as a second argument:
.. code-block:: twig
{{ numbers|reduce((carry, v, k) => carry + v * k, 10) }}
{{ numbers|reduce((carry, value, key) => carry + value * key, 10) }}
{# output 18 #}
Note that the arrow function has access to the current context.
@@ -27,9 +27,3 @@ Arguments
* ``arrow``: The arrow function
* ``initial``: The initial value
.. note::
Internally, Twig uses the PHP `array_reduce`_ function.
.. _`array_reduce`: https://www.php.net/array_reduce