PHP Implode function


PHP Implode function – It converts array into string. This function accepts array elements and returns the string of elements separated by delimiter. The function explode is reverse of the implode function. Both implode and explode functions are frequently used functions in php. We are going to describe the implode function with example and demo.


PHP Implode function Syntax

PHP Implode function Syntax

implode(separator, array);

Input Parameters

  • separator : Is used to put separator between array element you can pass null as “” if do not want to put anything between elements.
  • array : Array you want to convert to string.

Return value

It returns string.

Technical Requirement-

PHP Version : 4+

Let us understand implode function with examples.

PHP Implode function Example

Here is very basic example –

PHP implode example

$array = array('a','b','c','d');
$string = implode(" ", $array);
echo $string;

Try it »

In the above example array elements converted into string by separator space. The above example will produce the following outut-

PHP Implode function Example

PHP implode array comma separated Example

Here is another example with separator comma “,” –

PHP implode array comma separated

$array = array('a','b','c','d');
$string = implode(",", $array);
echo $string;

Try it »

The above example will produce following output-

PHP Implode function Example

PHP implode array pipe separated Example

Here is another example with separator pipepline “|” –

PHP implode array separator pipeline “|” Example

$array = array('a','b','c','d');
$string = implode("|", $array);
echo $string;

Try it »

The example will convert the array elements to string by pipeline separator. Here is the output of the above example –

PHP implode array comma separated string

If you want to perform reverse of this function use the function explode.

Note : PHP implode function is binary safe.

Advertisements

Add Comment

📖 Read More