array

A one- or multidimensional array.

Signatures

  • [...]

Details

Array variables can store a one- or multidimensional list of elements of another data type dtype. The usage of arrays is described in more details in section 'Arrays '.

Multidimensional arrays are always 'rectangular' meaning that each dimension has a fixed size that spans over all elements.

Example

 int a[][] = [[ 1, 2, 3 ],[ 4, 5, 6 ],[ 7, 8, 9 ],[ 10, 11, 12 ]]
 echo( a )
 echo( "length = " + a.length() )
 a.erase( 2 )
 echo( a )
 a.resize( 5 )
 echo( a )
 

Output

 <int>[[1,2,3],[4,5,6],[7,8,9],[10,11,12]]
 length = 4
 <int>[[1,2,3],[4,5,6],[10,11,12]]
 <int>[[1,2,3],[4,5,6],[10,11,12],[0,0,0],[0,0,0]]
 

Casts To

string

Members

int length()

Returns the size of the array, i.e. of its topmost dimension.

int erase( int n )

Removes the element with index n from the array. Returns the position that was erased. (Note that this operation has an asymptotic complexity of the number of elements after the one removed.)

push_back( dtype e )

Adds an element e to the end of the array. This increases the array length by one.

resize( int size )

Changes the size of the array to a new size size. If this is smaller than the former size, the supernumerary elements are at the end of the array get deleted.

See also