PHP implode()

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.

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours

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.

Code
Output

All contributors

Contribute to Docs

Learn PHP on Codecademy

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours