implode()

Anonymous contributor's avatar
Anonymous contributor
Anonymous contributor's avatar
Anonymous contributor
Published May 27, 2023
Contribute to Docs

The implode() function accepts an array of elements and an optional separator. It will return a string formed by combining the elements in their exact order along with the optional separator.

Syntax

implode($separator, $array)

implode() accepts the following parameters:

  • separator - Optional string value. If omitted, the default is an empty string.
  • array - An array of string elements to implode.

Example

The example below uses the implode() function to create the sentence ‘I love learning with Codecademy’. The separator is a single space.

<?php
$to_be_imploded = array('I','love','learning','with','Codecademy');
echo implode(' ',$to_be_imploded);
?>

Codebyte Example

The following example shows the use of implode() function with and without the use of the separator.

us
Visit us
code
Hide code
Code
Output
Hide output
Hide output
Loading...

All contributors

Looking to contribute?

Learn PHP on Codecademy