Skip to the content
Documentation

array

No ratings yet

Summary

Creates and returns a new array.

Usage

array( element1 [, element2 [, ... ] ] )

Parameters

Name Type Description Required
element1 any Element / value of any kind. Yes.
element2 any Another element / value of any kind. No.

Returns

An array containing the specified elements.

Description

This operator builds an array using the specified elements. The elements must be passed as parameters. The operator returns the resulting array.

Examples

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

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

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

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

Contributors

Comments (2 historical)

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

  1. element1 not required

    Bruce Morrison ·

    It is possible to create empty arrays but excluding element 1. The document is incorrect in sayng that element 1 is required.

  2. count($array)

    pike ·

    The documentation index doesnt mention count() in the arrays chapter
    count() is under miscellaneous .. but it works on arrays
    Example 1
    {array( 1, 2, 5 )|count()}
    The following output will be produced: "3".

Comments

Add a comment

Comments are read by a moderator before they appear.