Core Function Array

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

Contents

Description

Create a new array.

An array in Sputnik is actually an ordered map. A map is a type that associates values to keys. This type is optimized for several different uses; it can be treated as an array, list, hash table (an implementation of a map), dictionary, collection, stack, queue, and probably more. As array values can be other arrays, trees and multidimensional arrays are also possible.

Explanation of those data structures is beyond the scope of this page, but at least one example is provided for each of them. For more information, look towards the considerable literature that exists about this broad topic.

Parameters

expressions

Optional; One or more parameters to add to the array.

(If you ignore this and just like Array() it will create a blank array)


Return Value

A new array optionally populated with any expressions.

Remarks

None.

Example

A simple list

$array = array("One", "Two", "Three");
printr( $array );

A simple dictionary

$array = array(
    "foo" => "bar",
    "bar" => "foo"
);
printr( $array );

If multiple elements in the array declaration use the same key, only the last one will be used as all others are overwritten.

$array = array(
    1    => "a",
    "1"  => "b",
    1.5  => "c",
    true => "d"
);
printr( $array );

A large array

$array = array(
	// The only C0 controls acceptable in XML 1.0 and 1.1
	array("bottom" => 0x0009, "top" => 0x000A),
	array("bottom" => 0x000D, "top" => 0x000D),
 
	// Non-control characters in the Basic Latin block, excluding the last C0 control
	array("bottom" => 0x0020, "top" => 0x007E),
 
	// The only C1 control character accepted in both XML 1.0 and XML 1.1
	array("bottom" => 0x0085, "top" => 0x0085),
 
	// Rest of BMP, excluding all non-characters (such as surrogates)
	array("bottom" => 0x00A0, "top" => 0xD7FF),
	array("bottom" => 0xE000, "top" => 0xFDCF),
	array("bottom" => 0xFDE0, "top" => 0xFFFD),
 
	// Exclude all non-characters in supplementary planes
	array("bottom" => 0x10000, "top" => 0x1FFFD),
	array("bottom" => 0x20000, "top" => 0x2FFFD),
	array("bottom" => 0x30000, "top" => 0x3FFFD),
	array("bottom" => 0x40000, "top" => 0x4FFFD),
	array("bottom" => 0x50000, "top" => 0x5FFFD),
	array("bottom" => 0x60000, "top" => 0x6FFFD),
	array("bottom" => 0x70000, "top" => 0x7FFFD),
	array("bottom" => 0x80000, "top" => 0x8FFFD),
	array("bottom" => 0x90000, "top" => 0x9FFFD),
	array("bottom" => 0xA0000, "top" => 0xAFFFD),
	array("bottom" => 0xB0000, "top" => 0xBFFFD),
	array("bottom" => 0xC0000, "top" => 0xCFFFD),
	array("bottom" => 0xD0000, "top" => 0xDFFFD),
	array("bottom" => 0xE0000, "top" => 0xEFFFD),
	array("bottom" => 0xF0000, "top" => 0xFFFFD),
	array("bottom" => 0x100000, "top" => 0x10FFFD)
);
printr( $array );
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox