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.

replace

Summary

Replaces elements in an array.

Usage

input|replace( offset [, length [, element1 [, element2 [, ...]]] ] )

Parameters

NameTypeDescriptionRequired
offset integer The offset to start replacing elements. Yes
length integer The number of elements that should be replaced. No
element1 any The new element that will replace the old one. No
element2 any The new element that will replace the old one. No

Returns

A replaced version of the input array.

Description

This operator replaces elements(s) from the input array and a replaced version of input array will be returned. The "offset" parameter must be used to define the start of the portion that should be replaced. The "length" parameter can be used to define the number of elements that should be replaced. If length is omitted, the element(s) will be placed after the offset(like 'insert' operator).

Examples

Example 1

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

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

Example 2

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

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

Example 3

{array( 1, 2, 3, 4, 5 )|replace( 1, 2, 'a', 'b', 'c' )}

The following array will be returned: ( 1, 'a', 'b', 'c', 4, 5 ).

Example 4

{array( 1, 2, 3, 4, 5 )|replace( 1, , 'a', 'b', 'c' )}

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

Geir Arne Waaler (19/08/2010 9:14 am)

Geir Arne Waaler (19/08/2010 9:45 am)


Comments

There are no comments.