Return the first element of an array, using reset().
- Service:
CleverAge\ProcessBundle\Transformer\Array\ArrayFirstTransformer - Transformer code:
array_first
array. With the default options, any non-iterable value is accepted and returned unchanged.
any: the first element of the arrayfalseif the array is empty- the input value itself if it is not iterable and
allow_not_iterableisfalse
| Code | Type | Required | Default | Description |
|---|---|---|---|---|
allow_not_iterable |
bool |
false |
When false, a non-iterable input is returned unchanged (see Notes) |
['foo', 'bar', 'baz']becomes'foo'
# Transformer options level
array_first: ~The allow_not_iterable option behaves counter-intuitively: when set to true, the non-iterable check is skipped and
reset() is called on the raw value, which throws a \TypeError for scalar or null inputs (objects are accepted by
reset(), which then returns their first public property). Keep the default value.