PHP implode() function

The PHP implode() functions converts array to string using given separator. By using implode() function you can join all the array elements and form a string. implode() function works as same as the join() function in PHP. The implode function is binary safe and you can pass the array elements in any order.

Basic Syntax

string implode(separator,array)
Name Description
separator This is optional parameter used to place between two array elements. The default value is “”.
array array of elements to convert to string.

Return Value

The php implode function returns the string formed using array elements.


Following are the examples of implode() method.

1. Separating array elements by spaces using implode() function

$arr = array('Apple','Banana','Cat','Dog','Elephant');
echo implode(" ",$arr)."<br>";

The output should be:

Apple Banana Cat Dog Elephant

2. Separating array elements by comma using implode() function

$arr = array('White','Blue','Red','Orange','Voilet','Black');
echo implode(",",$arr)."<br>";

The output should be: