# 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="/files/-MKk9YjCz_YkVR1YiRy-" alt="" data-size="line">&#x20;

  > The string to separate each pair of adjacent elements.\
  > Default: `","`
* `$prefix` <img src="/files/-MKk9YjCz_YkVR1YiRy-" alt="" data-size="line">&#x20;

  > The prefix string.\
  > Default: `""`(empty)
* `$suffix`<img src="/files/-MKk9YjCz_YkVR1YiRy-" 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>" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://arrayutils.docs.present.kim/methods/g/join.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
