Swaps array values of an array at specified positions. This function is more efficient than multiple cfset tags
arraySwap(array, position1, position2)
returns boolean
someArray.swap(position1, position2)
Name | Type | Required | Default | Description |
---|---|---|---|---|
array | array | Yes | The array for which positions will be swapped | |
position1 | numeric | Yes | Position of 1st element to swap. | |
position2 | numeric | Yes | Position of 2nd element to swap. |
superiorArray = ['Spider-Man','Green Goblin','Doctor Octopus','Venom'];
arraySwap(superiorArray,1,3);
writeDump(superiorArray);
CF11+ or Lucee4.5+
superiorArray = ['Spider-Man','Green Goblin','Doctor Octopus','Venom'];
superiorArray.swap(1,3);
writeDump(superiorArray);