How PHP implode Function Join Array Element With String

What is the PHP implode function

An implode is the process where we convert and join the pieces of characters into a single string or sentence. The string pieces are the smallest parts of characters which you will get after the use of the PHP explode function.

PHP implode function reverses the modification of the sentence which you have obtained from PHP explode function.

Suppose there are some pieces of characters like “This”,”is”, “the”, “great”, “world” and after you use implode it converts the small pieces of elements into a string as given below:
1. This
2. is
3. the
4. great
5. world

The implode function group the array elements into string.

Why we use PHP implode() function

We can use the PHP implode function to convert an array elments into string of characters. A string of characters can be a group of words which you can call it as a sentence.
PHP implode is useful when you want to reverse the PHP explode effect and get some string of characters. The syntax of the PHP implode function is as given below:-

Check below table for the description of each parameter of the implode function of PHP.

Parameter Name Description
  • The separator is the required field where you can put the separator string you can put after the string conversion.
  • You can put spaces, dash, quotes in place of the separator.
  • This is also the required field. Here you have to put array you will get after the effect of PHP implode function.
  • An array is the homogeneous combination of similar data type.

Example of PHP implode() function converts array element into string

The below example contains the array which you can convert into a string using the implode function. Here in the given example, we are using the space as a separator between the string characters.

The output of this example is the sentence with some spaces between the words.
Example 1:


This is Tutorialdeep learning PHP function.

Example2: The example contains the dash(-) as the separator after you apply the implode function to the array. There are seven array values which you can combine using the PHP implode function.

Here, We are using the PHP echo statement to print the output of the implode function of the PHP.



Example 3 : You can also use any other separator like comma and a single space(, ). After you use the implode function with the separator, it will convert the array into a string of characters with the separator you want to to put among the chraracters.


200, 500, 101, 209, 767, 485, 987

Reference implode function.

You must also read:-