You are now viewing the documentation of eZ Publish legacy (4.x series and the legacy "stack" in 5.x). For 5.x versions this documentation must be complemented with the latest, more current documentation available at confluence.ez.no. Happy learning!

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 11:14 am)

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


Comments

There are no comments.