Twig
Twig copied to clipboard
Add syntax for destructuring assignment
Add destructuring assignment syntax that makes it possible to unpack values from arrays, or properties from objects, into distinct variables (as same is in Javascript):
A twig template
{% set [a, b] = [1, 2] %}
{% for {id, firstName, ...rest} in data %}
{% endfor %}
should be converted to
[$a, $b] = [1, 2];
foreach ($data as ['id' => $id, 'firstName' => $firstName]) {
// TODO support for ...rest
}
Is there any plan to include this is the near future? I would really like to use it