# Function Reference

# _ArraySwap

Swaps elements of a 1D array and full or part rows/columns of a 2D array

#include <Array.au3>
_ArraySwap ( ByRef $aArray, $iIndex_1, $iIndex_2 [, $bCol = False [, $iStart = -1 [, $iEnd = -1]]] )

## Parameters

$aArray | Array to modify
$iIndex_1 | Index of first element (1D) or row/column (2D) to swap
$iIndex_2 | Index of second element (1D) or row/column (2D) to swap
$bCol | [optional] If True then for 2D array above parameters refer to columns; if False (default) above parameters refer to rows
$iStart | [optional] Index in row/column to start swap (2D array only)
$iEnd | [optional] Index in row/column to end swap (2D array only)

## Return Value

Success: | 1
Failure: | -1 and sets the @error flag to non-zero.
@error: | 1 - $aArray is not an array 2 - $aArray is not a 1D or 2D array 3 - $iIndex_1 or $iIndex_2 is outside array bounds 4 - $iStart or $iEnd outside array bounds 5 - $iStart is greater than $iEnd

## Remarks

Optional parameters ignored for 1D arrays.

## Related

_ArrayReverse

## Example

    #include <Array.au3>

    Local $aArray[10] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

    _ArrayDisplay($aArray, "Original", Default, 8)
    _ArraySwap($aArray, 3, 7)
    _ArrayDisplay($aArray, "Swapped Elements 3 and 7", Default, 8)

    Local $aArray_Base[10][10]
    For $i = 0 To 9
        For $j = 0 To 9
            $aArray_Base[$i][$j] = $i & " - " & $j
        Next
    Next
    _ArrayDisplay($aArray_Base, "Original", Default, 8)

    $aArray = $aArray_Base
    _ArraySwap($aArray, 3, 7)
    _ArrayDisplay($aArray, "Swapped Rows 3 and 7 in all Cols", Default, 8)

    $aArray = $aArray_Base
    _ArraySwap($aArray, 3, 7, False, 2, 5)
    _ArrayDisplay($aArray, "Swapped Rows 3 and 7 in Cols 2 to 5", Default, 8)

    $aArray = $aArray_Base
    _ArraySwap($aArray, 3, 7, True)
    _ArrayDisplay($aArray, "Swapped Cols 3 and 7 in all Rows", Default, 8)

    $aArray = $aArray_Base
    _ArraySwap($aArray, 3, 7, True, 2, 5)
    _ArrayDisplay($aArray, "Swapped Cols 3 and 7 in Rows 2 to 5", Default, 8)