The implode Function

The implode function merges an array into a string with a specified separator.

Syntax

phpimplode(string $separator, array $array): string

Example

Let's merge an array into a string:

php<?php
  $arr = ['a', 'b', 'c', 'd', 'e'];
  echo implode('-', $arr);
?>

Code execution result:

php'a-b-c-d-e'

Example

Using an empty separator:

php<?php
  $arr = ['a', 'b', 'c', 'd', 'e'];
  echo implode('', $arr);
?>

Code execution result:

php'abcde'

See Also

  • the explode function,
    which splits a string into an array