Core Function InsertArray
(→arrays) |
m (1 revision) |
||
(3 intermediate revisions by one user not shown) | |||
Line 36: | Line 36: | ||
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(). | 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 === | ||
Line 50: | Line 52: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | Example of inserting more than one array at a time | |
<syntaxhighlight lang="sputnik"> | <syntaxhighlight lang="sputnik"> | ||
Line 58: | Line 60: | ||
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); |
Latest revision as of 12:37, 14 June 2015
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);