Skip to the content
Documentation

append

No ratings yet

Summary

Returns the input array with appended elements.

Usage

input|append( element1 [, element2 [, ... ] ] )

Parameters

Name Type Description Required
element1 any Element to be appended to the input array. Yes.
element2 any Another element to be appended to the input array. No.

Returns

An array consisting of the input array and the parameters.

Description

This operator appends the parameter value(s) at the end of the input array and returns the resulting array.

Examples

Example 1
{array( 1, 2, 3 )|append( 4, 5, 6 )}

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

Example 2
{array( 1, 2, 3 )|append( array( 4, 5, 6 )}

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

Contributors

  • Balazs Halasy Author Updated
  • John Commenter
  • Adrien Commenter
  • sh Commenter

Comments (3 historical)

Written by readers of the earlier documentation sites, kept as they were.

  1. How to append to a variable array ?

    John ·

    hello,
    Assuming I have a variable $A=array(1,2,3)
    and In a loop I need to append $article.node_id to this array ?
    how would i do that ?
    The only possible way is that i have to retype the array and append after it? and it didn't wok any where else
    please contact
    thanks

    1. Re: How to append to a variable array ?

      Adrien ·

      Let the array retype itself... In your loop, do something like
      {set $A = $A|append($article.node_id)}

  2. a bug

    sh ·

    I think there is a parse error in the sample, it'll works better like this
    {array( 1, 2, 3 )|append( array( 4, 5, 6 ))}

Comments

Add a comment

Comments are read by a moderator before they appear.