# join()

{% code title="Example.php" %}

```php
<?php use kim\present\utils\arrays\ArrayUtils;

$arrayUtils = ArrayUtils::from(["Apple", "Banana", "Carrot"]);

//Joining array with multiple elements
$arrayUtils->join();         // "Apple,Banana,Carrot"
$arrayUtils->join(" and ");  // "Apple and Banana and Carrot"
$arrayUtils->join(" || ");   // "Apple || Banana || Carrot"

//Joining with prefix
$arrayUtils->join(" and ", "I like ");
// expected output: "I like  Apple and Banana and Carrot"

//Joining with prefix and suffix
$arrayUtils->join(" and ", "I like ", " little bit");
// expected output: "I like Apple and Banana and Carrot little bit"
```

{% endcode %}

## Syntax

```php
$arrayUtils->join(string $glue = ",", string $prefix = "", string $suffix = "") : string;
```

### Parameter

* `$glue` <img src="https://2976351099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MKYhyHaArG9Gsnmdxc8%2F-MKk9I82AGQBHkmwnVvk%2F-MKk9YjCz_YkVR1YiRy-%2FBADGE_OPTIONAL.svg?alt=media&#x26;token=3fbbac84-2f1b-40af-a991-b2eff659866a" alt="" data-size="line">&#x20;

  > The string to separate each pair of adjacent elements.\
  > Default: `","`
* `$prefix` <img src="https://2976351099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MKYhyHaArG9Gsnmdxc8%2F-MKk9I82AGQBHkmwnVvk%2F-MKk9YjCz_YkVR1YiRy-%2FBADGE_OPTIONAL.svg?alt=media&#x26;token=3fbbac84-2f1b-40af-a991-b2eff659866a" alt="" data-size="line">&#x20;

  > The prefix string.\
  > Default: `""`(empty)
* `$suffix`<img src="https://2976351099-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MKYhyHaArG9Gsnmdxc8%2F-MKk9I82AGQBHkmwnVvk%2F-MKk9YjCz_YkVR1YiRy-%2FBADGE_OPTIONAL.svg?alt=media&#x26;token=3fbbac84-2f1b-40af-a991-b2eff659866a" alt="" data-size="line">&#x20;

  > The suffix string.\
  > Default: `""`(empty)

### Return value

* A string with all array elements joined

## Prefixing

```php
ArrayUtils::joinFrom(iterable $from, string $glue = ",", string $prefix = "", string $suffix = "") : string;
```

## References

{% embed url="<https://www.php.net/manual/en/function.implode>" %}

{% embed url="<https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join>" %}
