# Array Reverse

## Recommended Posts

_ArrayReverse work only on 1D array so....

__ReverseArray which work on 1D & 2D Array

#include <Array.au3>

Local \$Eg_1[][] = [['A', 1, 11], ['B', 2, 22], ['C', 3, 33], ['D', 4, 44], ['E', 5, 55], ['F', 6, 66], ['G', 7, 77], ['H', 8, 88]]
_ArrayDisplay(\$Eg_1)
_ArrayDisplay(__ReverseArray(\$Eg_1))
_ArrayDisplay(__ReverseArray(\$Eg_1, 2, 5))

Local \$Eg_2[] = [1, 2, 3, 4, 5, 6, 7, 8]
_ArrayDisplay(\$Eg_2)
_ArrayDisplay(__ReverseArray(\$Eg_2))
_ArrayDisplay(__ReverseArray(\$Eg_2, 2, 5))

; #FUNCTION# =============================================================================
; Name...........: __ReverseArray
; Description ...:
; ========================================================================================
Func __ReverseArray(\$o_Array, \$o_StartPoint = 0, \$o_EndPoint = UBound(\$o_Array) - 1)
If Not IsArray(\$o_Array) Then Return SetError(1)
If \$o_StartPoint < 0 Then Return SetError(1)
If \$o_StartPoint >= \$o_EndPoint Then Return SetError(1)
If \$o_EndPoint > (UBound(\$o_Array) - 1) Then Return SetError(1)

Local \$o_Column = UBound(\$o_Array, 2)
If \$o_Column <= 1 Then \$o_Column = 1

Local \$o_Prefix = ''
Local \$o_Suffix = ''

If \$o_StartPoint > 0 Then _
\$o_Prefix = _ArrayToString(\$o_Array, (\$o_Column <= 1 ? @CRLF : '|'), 0, \$o_StartPoint - 1, @CRLF, -1, -1) & @CRLF

If \$o_EndPoint < (UBound(\$o_Array) - 1) Then _
\$o_Suffix = @CRLF & _ArrayToString(\$o_Array, (\$o_Column <= 1 ? @CRLF : '|'), \$o_EndPoint + 1, UBound(\$o_Array) - 1, @CRLF, -1, -1)

Local \$o_ArrayExt = _ArrayExtract(\$o_Array, \$o_StartPoint, \$o_EndPoint, -1, -1)

Local \$o_String = ''
For \$i = UBound(\$o_ArrayExt) - 1  To 0 Step -1
\$o_String &= _ArrayToString(\$o_ArrayExt, '|', \$i, \$i, '|', -1, -1) & @CRLF
Next
\$o_String = StringTrimRight(\$o_String, 2)

Local \$x_Array[0][\$o_Column]
Local \$o_Temp = \$o_Prefix & \$o_String & \$o_Suffix

Return \$x_Array
EndFunc

## Create an account

Register a new account

• ### Recently Browsing   0 members

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
×
• Create New...