Core Function InsertArray
(→arrays) |
(→Example) |
||
Line 50: | Line 50: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | Example of inserting more than one array at a time | |
<syntaxhighlight lang="sputnik"> | <syntaxhighlight lang="sputnik"> | ||
Line 58: | Line 58: | ||
insertArray($arr, 1, $otherArr, $anotherArr); | insertArray($arr, 1, $otherArr, $anotherArr); | ||
+ | |||
+ | printr($arr); | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | Example of casting a non-array as an array | ||
+ | |||
+ | <syntaxhighlight lang="sputnik"> | ||
+ | my $arr = array("One", "Five"); | ||
+ | my $otherArr = array("Three", "Four"); | ||
+ | my $value = "Two"; | ||
+ | |||
+ | insertArray($arr, 1, (array)$value, $otherArr); | ||
printr($arr); | printr($arr); |
Revision as of 09:41, 26 August 2013
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().
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);