join

Modified on Thu, 9 Jul at 10:49 AM

join

TABLE OF CONTENTS

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

Transformation
{
  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'}`)  

}
Result
{
  "a": "dragon, fruit",
  "b": "dragonfruit",
  "c": "dragon, False,  , , fruit",
  "d": "1",
  "e": "1.1",
  "f": "",
  "g": "",
  "h": ""
}

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article