php8.5
Home/ Manual/ strings / functions/ implode

implode

PHP function Edit on GitHub ✎

(PHP 4, PHP 5, PHP 7, PHP 8)

Join array elements with a string

Description

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

Alternative signature (not supported with named arguments):

implode(array $array): string

Legacy signature (deprecated as of PHP 7.4.0, removed as of PHP 8.0.0):

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

Join array elements with a separator string.

Parameters

separator

Optional. Defaults to an empty string.

array

The array of strings to implode.

Return Values

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

Changelog

VersionDescription
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.

Examples

implode() example

php
<?php

$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"

?>

Notes Bin-safe

See Also

Source: reference/strings/functions/implode.xml · from the official PHP manual (php/doc-en)