Caution: This documentation is for eZ Publish legacy, from version 3.x to 6.x.
For 5.x documentation covering Platform see eZ Documentation Center, for difference between legacy and Platform see 5.x Architecture overview.

insert

Summary

Inserts an element/sequence at specified position in an array.

Usage

input|insert( offset, element1 [, element2 [, ... ] ] )

Parameters

NameTypeDescriptionRequired
offset integer The offset where the element(s) should be inserted at. Yes.
element1 any An element that should be inserted into the existing array. Yes.
element2 any Another element that should be inserted into the existing array. No.

Returns

An array containing a combination of the original array and the inserted elements.

Description

This operator inserts an element or a sequence of elements at a specified position within the input. The resulting array will be returned (original array with the inserted values).

Examples

Example 1

{array( 1, 2, 5 )|insert( 2, 3, 4 )}

The following array will be returned: ( 1, 2, 3, 4, 5 ).

Balazs Halasy (05/02/2004 9:32 am)

Balazs Halasy (04/05/2005 1:38 pm)


Comments

  • Better Example

    I found this example to be a bit unreadable at first, since it was ambiguous that 2 was the offset, and not another item to add to the array. Clearer version:

    {array( 'a', 'b', 'e' )|insert( 2, 'c', 'd' )}

    The following array will be returned: ( 'a', 'b', 'c', 'd', 'e' ).