How to swap array values at specified positions in ColdFusion

ArraySwap() - swap array values of an array at specified positions

ArraySwap.cfm


<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>ArraySwap function example: how to swap array values of an array at specified positions</title>
</head>

<body>
<h2 style="color:Green">ArraySwap Function Example</h2>

<cfset ColorArray = ArrayNew(1)>
<cfset ArrayAppend(ColorArray,"Red")>
<cfset ArrayAppend(ColorArray,"Green")>
<cfset ArrayAppend(ColorArray,"Blue")>
<cfdump var="#ColorArray#" label="ColorArray">

<br />
<cfset Temp = ArraySwap(ColorArray,1,3)>
<cfdump var="#ColorArray#" label="ColorArray[After Swap Position 1,3]">
</body>
</html>






More ColdFusion examples