Core Function Join

From Sputnik Wiki
(Difference between revisions)
Jump to: navigation, search
m (1 revision)
 
(2 intermediate revisions by one user not shown)
Line 1: Line 1:
 
<pre>
 
<pre>
Array( <expressions> )  
+
Join( <array>, <separator> )
 
</pre>
 
</pre>
  
 
=== Description ===
 
=== Description ===
  
Create a new array.
+
Join an array into a string with an optional separator.
  
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.
+
=== Parameters ===
  
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.
+
==== array ====
  
=== Parameters ===
+
The array to join.
  
==== expressions ====
+
==== separator ====
  
Optional; One or more parameters to add to the array.
+
Optional; A string to place between each array element.
 
+
(If you ignore this and just like Array() it will create a blank array)
+
  
 +
Default is " " a space.
  
 
=== Return Value ===
 
=== Return Value ===
  
A new array optionally populated with any expressions.
+
Success - The array merged into a string.
 +
 
 +
Failure - Returns an empty string.
  
 
=== Remarks ===
 
=== Remarks ===
  
None.
+
This does not alter the original array.
  
 
=== Example ===
 
=== Example ===
  
A simple list
 
 
<syntaxhighlight lang="sputnik">
 
<syntaxhighlight lang="sputnik">
$array = array("One", "Two", "Three");
+
$days = Array ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
printr( $array );
+
Foreach ( $days as $day )
</syntaxhighlight>
+
{
 
+
println("Element is: " . $day);
A simple dictionary
+
}
<syntaxhighlight lang="sputnik">
+
println("Joined together is " . join($days, ":") );
$array = array(
+
// Prints: Joined together is Sun:Mon:Tue:Wed:Thu:Fri:Sat
    "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]]

Latest revision as of 12:38, 14 June 2015

Join( <array>, <separator> )

Contents

Description

Join an array into a string with an optional separator.

Parameters

array

The array to join.

separator

Optional; A string to place between each array element.

Default is " " a space.

Return Value

Success - The array merged into a string.

Failure - Returns an empty string.

Remarks

This does not alter the original array.

Example

$days = Array ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
Foreach ( $days as $day )
{
	println("Element is: " . $day);
}
println("Joined together is " . join($days, ":") );
// Prints: Joined together is Sun:Mon:Tue:Wed:Thu:Fri:Sat
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox