Lasso Soft Inc. > Home

[ array->exchange ]

Method

Exchanges the two elements within the array.

Note: This method will fail if one of the parameters is larger or smaller than the number of elements in the array.

  • Syntax
array->exchange(first_position, second_position)
Examples
  • Beginner

Swap the position of two elements in an array

This example exchanges the 2nd and 5th elements of an array.

Code

var( myArray = array('one', 'two', 'three', 'four', 'five', 'six', 'seven') )
//output original array
$myArray
'\n'
$myArray->exchange(2,5)
//output modified array
$myArray

Result

array(one, two, three, four, five, six, seven)
array(one, five, three, four, two, six, seven)

Recent Comments

No Comments found

Please note that periodically LassoSoft will go through the notes and may incorporate information from them into the documentation. Any submission here gives LassoSoft a non-exclusive license and will be made available in various formats to the Lasso community.

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft