PHP 8 reference · String Functions

PHP implode() Function

Join array elements into one string with a separator between them. join() is an alias of implode().

PHP 8 Since 4.0

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

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

Parameters

ParameterDescription
separator optional The text placed between elements. Default: ""
array The values to join.

Return value

A single string.

Examples

Join with and without a separatorTry it yourself
<?php
$tags = ["php", "arrays", "strings"];
echo implode(", ", $tags), "\n";
echo implode($tags), "\n";

Output

php, arrays, strings
phparraysstrings
Build a query stringTry it yourself
<?php
$params = ["page" => 2, "sort" => "name"];
$pairs = [];
foreach ($params as $k => $v) {
    $pairs[] = "$k=$v";
}
echo implode("&", $pairs), "\n";

Output

page=2&sort=name

Version history

VersionChange
PHP 4.0Added
PHP 8.0The old order implode($array, $separator) is no longer supported.

In other languages

Was this page helpful?