Lasso Soft Inc. > Home

[ array->merge ]

Method

[array->merge] merges an array parameter into the array. Accepts an array parameter and three integer parameters that identify which items from the array parameter should be inserted into the array. Defaults to inserting the entire array parameter at the end of the array. Returns no value.

The first element in an array is at index 1. An error is returned if any of the indexes specified are beyond the size of the arrays.

The first integer parameter specifies at which index in the base array the merge array should be inserted. Defaults to the end of the base array.

The second integer parameter specifies an offset into the merge array. Elements after this merge index will be copied into the base array. By default, the entire merge array will be copied.

The third integer parameter specifies the number of elements from the merge array which should be copied. By default all elements in the merge array after the merge index will be copied.

  • Syntax
base_array->Merge(merge_array)

base_array->Merge(merge_array, base_array_index)

base_array->Merge(merge_array, base_array_index, merge_array_index)

base_array->Merge(merge_array, base_array_index, merge_array_index, merge_array_num_elements)
Examples
  • Beginner

Merging two arrays:

Use the [array->merge] method.

Example 1:

The following example merges two arrays, each of which contains a portion of the days of the week. The resulting array is output.

Code

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

$DaysOfWeek->merge($MoreDays);
//output updated Array
$DaysOfWeek;

Result

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

Example 2:

Merge the second array into the first array at position 2.

Code

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

$DaysOfWeek->merge($MoreDays, 2);
//output updated Array
$DaysOfWeek;

Result

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

Example 3:

Merge the last 2 elements of the second array into the first array at position 3

Code

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

$DaysOfWeek->merge($MoreDays, 3, 2);
//output updated Array
$DaysOfWeek;

Result

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

Example 4:

Merge the first 2 elements of the second array into the first at position 1.

Code

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

$DaysOfWeek->merge($MoreDays, 1, 1, 2);
//output updated Array
$DaysOfWeek;

Result

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

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