Lasso Soft Inc. > Home

[ array->remove ]

Method

[array->remove] removes an item from the array.

Accepts a single integer parameter identifying the position of the item to be removed. Defaults to the last item in the array. An optional length parameter may be added which specifies how many items are to be removed from the array beginning with the one specified (ie. array->remove(2,1) is the same as array->remove(2). )

The first element in an array is at position 1. An error is returned if the position specified is beyond the size of the array or if the sum of the number of elements to be removed and the position of the starting element is more than the size of the array.

Note: The specified element(s) in the array is(are) removed and the positions of all elements in the array above the position are adjusted down as required.

  • Syntax
array->remove()

array->remove( element_position )

array->remove( element_position, number_of_elements )
Examples
  • Beginner

To remove an element from an array:

Use the [array->remove] method.

Example 1:

The following example removes the third element, Tue, from an array of the days of the week. The remainder of the array is output.

Code

var( DaysOfWeek = array('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat') )

$DaysOfWeek->remove(3)
$DaysOfWeek

Result

array(Sun, Mon, Wed, Thu, Fri, Sat)

Example 2:

This example removes the middle three days (Tue, Wed, Thu) from an array of the days of the week.

Code

var( DaysOfWeek = array('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat') )

$DaysOfWeek->remove(3,3)
$DaysOfWeek

Result

array(Sun, Mon, Fri, Sat)

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 2014 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft