array_reverse

This function returns a new array with all the elements from the given array (or a range of it) in a reversed order.

You can also reverse only a part of the array by supplying Offset And Length values. In this case the returned array will have a length corresponding to the range given by these values (e.g. if offset and length refer to a range of 5 elements then the new array will contain 5 elements).

 

Syntax:

array_reverse(array, [offset], [length]);

ArgumentTypeDescription
arrayArrayThe array to reverse
offsetRealOPTIONAL The offset, or the starting index, in the array. Setting a negative value will count from the end of the array. The starting index will then be array_length(array) + offset. See: Offset And Length
lengthRealOPTIONAL The number of elements to traverse. A negative value will traverse the array backwards (i.e. in descending order of indices, e.g. 2 > 1 > 0 instead of 0 > 1 > 2). See: Offset And Length

 

Returns:

Array

 

Example:

countdown = [5, 4, 3, 2, 1, 0];

countdown_reverse = array_reverse(countdown);

The above code creates an array countdown. It then creates an array countdown_reverse with the same elements but reversed.