Core Function Unshift

From Sputnik Wiki
Jump to: navigation, search
Unshift( <array>, <expressions> )

Contents

Description

Add items to the beginning of an array

Parameters

array

The array to use.

expressions

One or more values to add to the array.

Return Value

Success - Returns how many elements were done.

Failure - Returns 0.

Remarks

None

Example

$array = array ( "Two", "Three" );
 
unshift($array, "One");
unshift($array, "Zero", "Oh my!");
 
$i = 0;
Foreach ( $array as $i )
{
	println("Element ($i) is: " . $i);
	$i++;
}

Alternative method using the ..= operator

$array = array ( "Two", "Three" );
 
$array ..= array("One");
$array ..= array("Zero", "Oh my!");
 
$i = 0;
Foreach ( $array as $i )
{
	println("Element ($i) is: " . $i);
	$i++;
}
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox