Core Function Join

From Sputnik Wiki
(Difference between revisions)
Jump to: navigation, search
(Example)
Line 1: Line 1:
 
<pre>
 
<pre>
Join( <array>, <separator> )
+
Array( <expressions> )  
 
</pre>
 
</pre>
  
 
=== Description ===
 
=== Description ===
  
Join an array into a string with an optional separator.
+
Create a new array.
  
=== Parameters ===
+
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.
  
==== array ====
+
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.
  
The array to join.
+
=== Parameters ===
  
==== separator ====
+
==== expressions ====
  
Optional; A string to place between each array element.
+
Optional; One or more parameters to add to the array.
 +
 
 +
(If you ignore this and just like Array() it will create a blank array)
  
Default is " " a space.
 
  
 
=== Return Value ===
 
=== Return Value ===
  
Success - The array merged into a string.
+
A new array optionally populated with any expressions.
 
+
Failure - Returns an empty string.
+
  
 
=== Remarks ===
 
=== Remarks ===
  
This does not alter the original array.
+
None.
  
 
=== Example ===
 
=== Example ===
  
 +
A simple list
 
<syntaxhighlight lang="sputnik">
 
<syntaxhighlight lang="sputnik">
$days = Array ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
+
$array = array("One", "Two", "Three");
Foreach ( $days as $day )
+
printr( $array );
{
+
</syntaxhighlight>
println("Element is: " . $day);
+
 
}
+
A simple dictionary
println("Joined together is " . join($days, ":") );
+
<syntaxhighlight lang="sputnik">
// Prints: Joined together is Sun:Mon:Tue:Wed:Thu:Fri:Sat
+
$array = array(
 +
    "foo" => "bar",
 +
    "bar" => "foo"
 +
);
 +
printr( $array );
 +
</syntaxhighlight>
 +
 
 +
If multiple elements in the array declaration use the same key, only the last one will be used as all others are overwritten.
 +
 
 +
<syntaxhighlight lang="sputnik">
 +
$array = array(
 +
    1    => "a",
 +
    "1"  => "b",
 +
    1.5  => "c",
 +
    true => "d"
 +
);
 +
printr( $array );
 +
</syntaxhighlight>
 +
 
 +
A large array
 +
<syntaxhighlight lang="sputnik">
 +
$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 );
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
[[Category:Core Function]]
 
[[Category:Core Function]]

Revision as of 14:31, 18 August 2013

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