Core Function InsertArray

From Sputnik Wiki
Jump to: navigation, search
InsertArray( <array>, <id>, <arrays> )

Contents

Description

Add arrays to an array at a given location

Parameters

array

The array to use.

id

Location to insert to.

Note - If location doesnt exist it will be created and the void between arrays end and your new index will be empty strings.

arrays

One or more arrays to add to the array.

Note - Arrays are required here and an exception will trigger if these parameters are not arrays.

To avoid issues see the example below for casting a normal value as an array.

Return Value

Success - Returns how many elements were done.

Failure - Returns false.

Remarks

Rather than adding the array as a value in a single index it will unravel the array and insert its values as if each value had been passed individually with insert().

Note - This is inserting the values and not the keys.

Example

Example of just inserting one array

my $arr = array("One", "Five", "Six");
my $otherArr = array("Two", "Three", "Four");
 
insertArray($arr, 1, $otherArr);
 
printr($arr);

Example of inserting more than one array at a time

my $arr = array("One", "Six");
my $otherArr = array("Two", "Three");
my $anotherArr = array("Four", "Five");
 
insertArray($arr, 1, $otherArr, $anotherArr);
 
printr($arr);

Example of casting a non-array as an array

my $arr = array("One", "Five");
my $otherArr = array("Three", "Four");
my $value = "Two";
 
insertArray($arr, 1, (array)$value, $otherArr);
 
printr($arr);
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox