jmf / twig-array
用于在Twig模板中与数组交互的扩展。
1.0.0
2024-06-05 02:59 UTC
Requires
- php: >=8.3
- twig/twig: ^3.0
Requires (Dev)
- phing/phing: ^2.17
- phpmd/phpmd: ^2.13
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^11.1
- rector/rector: ^1.0
- squizlabs/php_codesniffer: ^3.8
README
安装与要求
使用Composer安装Composer
composer require jmf/twig-array
在Twig模板中的使用
array_set()
设置数组中的特定键。
{% set values = {} %} {% set values = values|array_set('foo', 'bar') %}
array_unset()
取消设置数组中的特定键。
{% set values = {'foo': 'bar'} %} {% set values = values|array_unset('foo') %}
array_push()
将新值追加到数组末尾。
{% set values = {'foo'} %} {% set values = values|array_push('bar') %}
array_pop()
移除数组的最后一个元素。
{% set values = {'foo', 'bar'} %} {% set values = values|array_pop() %}
array_unshift()
将新值追加到数组开头。
{% set values = {'foo'} %} {% set values = values|array_unshift('bar') %}
array_shift()
移除数组的第一个元素。
{% set values = {'foo', 'bar'} %} {% set values = values|array_shift() %}