PHP implode() Function
Example
Combine array elements into a string:
Run Example »
Definition and Usage
The implode() function returns a string formed by joining array elements.
**Note:** The implode() function accepts two parameter orders. However, for historical reasons,explode() does not work; you must ensure the separator parameter comes before the string parameter.
**Note:** The separator parameter of the implode() function is optional. But for backward compatibility, it is recommended to use two parameters.
**Note:** This function is binary-safe.
Syntax
implode(
separator,array
)
| Parameters | Description |
|---|---|
| separator | Optional. Specifies what is placed between array elements. Default is "" (an empty string). |
| array | Required. The array to combine into a string. |
Technical Details
| Return Value: | Returns a string formed by joining array elements. |
|---|---|
| PHP Version: | 4+ |
| Changelog: | In PHP 4.3.0,separator parameter became optional. |
More examples
Example 1
Separate array elements with different characters:
"; echo implode("+",$arr).""; echo implode("-",$arr)."
"; echo implode("X",$arr); ?>
Run Example »
PHP String Reference Manual