Loader

implode

Join array elements with a glue string. Test implode online.

string implode ( string $glue , array $pieces )

string implode ( array $pieces )

The array of strings to implode. Every new line as one array element.

PHP Documentation by the PHP Documentation Group

implode

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

implodeJoin 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

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

Version Description
8.0.0 Passing the separator after the array is no longer supported.
7.4.0 Passing the separator after the array (i.e. using the legacy signature) 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

PHP Documentation

Copyright © 1997 - 2016 by the PHP Documentation Group. This material may be distributed only subject to the terms and conditions set forth in the Creative Commons Attribution 3.0 License or later. A copy of the Creative Commons Attribution 3.0 license is distributed with this manual. The latest version is presently available at » http://creativecommons.org/licenses/by/3.0/.