join

Join strings from an array with a given separator

Definition

string join(string $separator, array[string] $stringsarray)

Joins strings from $stringsarray with $separator in between them.

Parameters

string $separator

Separator to use between elements of $stringsarray.

array[string] $stringsarray

Array of strings to be joined.

Returns

string

Single string consisting of all elements from $stringsarray with $separator in between them.

Examples

{
  a: join(', ', ['dragon', 'fruit']),	
  b: join('', ['dragon', 'fruit']),
  c: join(', ', ['dragon', `false`, ' ', `null`, 'fruit']),	
  d: join(', ', [`1.0`]),
  e: join(', ', [`1.1`]),
  f: join(' - ', [`null`]),
  g: join(', ', `[]`),
  h: join(', ', `{dragon: 'fruit'}`)	
}
{
  "a": "dragon, fruit",
  "b": "dragonfruit",
  "c": "dragon, False,  , , fruit",
  "d": "1",
  "e": "1.1",
  "f": "",
  "g": "",
  "h": ""
}