Return the element at a given position of an array, using array_slice(). The position is based on the order of the
elements, not on their keys, so it also works with associative arrays. Negative indexes are counted from the end.
- Service:
CleverAge\ProcessBundle\Transformer\Array\ArrayElementTransformer - Transformer code:
array_element
array
any: the element found at the given position
| Code | Type | Required | Default | Description |
|---|---|---|---|---|
index |
int |
X | Position of the element (0-based, a negative value starts from the end) |
- Get the 2nd element:
['foo', 'bar', 'baz']becomes'bar'
# Transformer options level
array_element:
index: 1- Get the penultimate element:
['foo', 'bar', 'baz']becomes'bar'
# Transformer options level
array_element:
index: -2There is no bound check: an index outside the array triggers an "Undefined array key" warning.