-1.4 C
New York
Wednesday, November 29, 2023

PHP implode() Function

What is implode() function in PHP

The implode() function is a binary-safe function in PHP, which used to join elements of an array. It merges all the elements of an array and returns a string. 


implode(separator, array)


The implode() function takes two parameters one optional and one compulsory.

Parameter Type Description
separator (optional) string type

This parameter separates the elements of an array joined to form a string.

Default value: empty string

array (mandatory) array This parameter specifies the array whose elements are to be imploded (joined)


  • PHP implode() accepts its parameter in either order.
  • The separator parameter in implode() function became optional in PHP version  4.3.0, but it is recommended to use atleast two-parameter for backward compatibility.

Return Value: 

This function returns a string containing all the elements of input array in the same order, along with separator(if specified).

Example of implode() function in PHP


//PHP Program to illustrate the working of implode() function

//Array Variable
$cars = array('Maruti','Hyundai','Honda','Toyota','JEEP');
//Variable to store the data after implode
$implodeCars = implode(", ", $cars);
//Printing the output


Maruti, Hyundai, Honda, Toyota, JEEP???????


Related Articles

Latest Articles