implode()

implode() — Join array elements with a string.

Built-in function of PHP 8.5. The manual lists it as available in PHP 4, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.

Signature

implode(string $separator, array $array): string implode(array $array): string implode(array $array, string $separator): string

Parameters

ParameterTypeWhat it takes
$separatorstringOptional. Defaults to an empty string.
$arrayarrayThe array of strings to implode.

Return value

Returns a string containing a string representation of all the array elements in the same order, with the separator string between each element.

Example

A runnable snippet:

$array = ['lastname', 'email', 'phone']; var_dump(implode(",", $array)); // string(20) "lastname,email,phone" // Empty string when using an empty array: var_dump(implode('hello', [])); // string(0) "" // The separator is optional: var_dump(implode(['a', 'b', 'c'])); // string(3) "abc"

Changelog

VersionChange
8.0.0Passing the separator after the array is no longer supported.
7.4.0Passing the separator after the array (i.e. using the legacy signature) has been deprecated.

See also

explode(), preg_split(), http_build_query()

All PHP 8.5 built-in functions

Reference card built from the PHP manual page implode() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.