implode

(PHP 4, PHP 5, PHP 7)

implodeJoin array elements with a string

Description

implode ( string $glue , array $pieces ) : string
implode ( array $pieces ) : string

Join array elements with a glue string.

Note:

implode() can, for historical reasons, accept its parameters in either order. For consistency with explode(), however, it is deprecated not to use the documented order of arguments.

Parameters

glue

Defaults to an empty string.

pieces

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 glue string between each element.

Changelog

Version Description
7.4.0 Passing the glue after the pieces (i.e. not using the documented order of parameters) has been deprecated.

Examples

Example #1 implode() example

<?php

$array = array('lastname', 'email', 'phone');
$comma_separated = implode(",", $array);

echo $comma_separated; // lastname,email,phone

// Empty string when using an empty array:
var_dump(implode('hello', array())); // string(0) ""

?>

Notes

Note: This function is binary-safe.

See Also

© 1997–2020 The PHP Documentation Group
Licensed under the Creative Commons Attribution License v3.0 or later.
https://www.php.net/manual/en/function.implode.php