❮ PHP String Reference
Example
Join array elements with a string:
Try it Yourself »
Definition and Usage
The implode[] function returns a string from the elements of an array.
Note: The implode[] function accept its parameters in either order. However, for consistency with explode[], you should use the documented order of arguments.
Note: The separator parameter of implode[] is optional. However, it is recommended to always use two parameters for backwards compatibility.
Note: This function is binary-safe.
Syntax
Parameter Values
separator | Optional. Specifies what to put between the array elements. Default is "" [an empty string] |
array | Required. The array to join to a string |
Technical Details
Returns a string from elements of an array |
4+ |
The separator parameter became optional in PHP 4.3.0 |
More Examples
Example
Separate the array elements with different characters:
Try it Yourself »
❮ PHP String Reference
❮ PHP String Reference
Example
Break a string into an array:
Try it Yourself »
❮ PHP String Reference
[PHP 4, PHP 5, PHP 7, PHP 8]
implode — 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
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
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
Notes
Note: This function is binary-safe.
See Also
- explode[] - Split a string by a string
- preg_split[] - Split string by a regular expression
- http_build_query[] - Generate URL-encoded query string
houston_roadrunner at yahoo dot com ¶
13 years ago
it should be noted that an array with one or no elements works fine. for example: