Core Function Array Splicing

From Sputnik Wiki
Jump to: navigation, search
$newArray = $Array[ .. .. . . . . ]

Contents

Description

Copy parts out of an array and return them as a new array

Parameters

There is no limit.

Remarks

All actions apply to the array and only return VALUES not keys.

Splicing can overlap and return the same item more than once.

Spicing likes to use patterns such as:

'A'..'Z'
c65..c69
0..10
10..0
0x0A..0x65
$valuea to $valueb

If anything else is entered it will return the KEY that it links to.

Example

Extract elements 0 to 3 from an array

$Test = array("Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight");
printr($Test[0..3]);

Extract elements 3 to 0 from an array

$Test = array("Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight");
printr($Test[3..0]);

Extract elements 0 to 3 AND 5 to 6 from an array

$Test = array("Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight");
printr($Test[0..3, 5..6]);

Extract elements 0 to 3 AND 5 to 6 AND 7 from an array

$Test = array("Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight");
printr($Test[0..3, 5..6, 7]);

Extract elements 0 to 3 AND 5 to 6 AND 7 to 1 from an array

$Test = array("Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight");
printr($Test[0..3, 5..6, 7..1]);

Extract a value out a dictionary (For whatever reason)

$Test = array(	"A" => "Zero",
				"B" => "One",
				"C" => "Two",
				"D" => "Three",
				"E" => "Four",
				"F" => "Five",
				"G" => "Six", 
				"H" => "Seven", 
				"I" => "Eight");
 
 
printr($Test['G']);

Extract a some of values out a dictionary

$Test = array(	"A" => "Zero",
				"B" => "One",
				"C" => "Two",
				"D" => "Three",
				"E" => "Four",
				"F" => "Five",
				"G" => "Six", 
				"H" => "Seven", 
				"I" => "Eight");
 
 
printr($Test['G'..'H']);

Extract a series of values out a dictionary

$Test = array(	"A" => "Zero",
				"B" => "One",
				"C" => "Two",
				"D" => "Three",
				"E" => "Four",
				"F" => "Five",
				"G" => "Six", 
				"H" => "Seven", 
				"I" => "Eight");
 
 
printr($Test['G'..'H', 'F'..'D', 'B']);
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox