What is the difference between Implode and Explode functions in PHP?

Spread the love

Hi folk,

In this tutorial, we are going to learn the basic concept of implode and explode functions in PHP and also learn how to use implode and explode functions in PHP  with examples.

Implode and explode functions is one of the most powerful built-in function in PHP.implode in PHP is known is “array to string function” which join the element of an array into a string and explode in PHP is know is the “string to array ” function which split a string into a small string to form an array of strings.

PHP implode() function:

The PHP implode function is used to “to join elements of an array to make a string”  also know is array to string function because it basically takes an array of string and join the element of the array into a form of string using delimiter( separator) and then return that string value.

Array.Implode() function is basically is an  alias for  the builtin function php.join() the work of implode function is exactly the same of php.join()function.

Whenever we have an array and if we want to make a string from the elements of the array we simply use implode function to get the required result.

Syntax of the implode()function:


The implode function in PHP basically take to two parameters one of them is optional and another one is mandatory and it also has a return type string


This is the first parameter of the implode function is called glue or separator which is optional but the use of both parameters is recommended for backward compatibility.


The second parameter is pieces which are actually the array of the element which we want to join to a string.

Return type:

The return type is a string which returns the string value which is created from the array’s elements.

For example:


implode and explode function

PHP explode() function:

Explode in PHP  is one of the powerful built-in function in PHP which is used to “make an array from a string value.”
it basically split a string of values into a small string using specific delimiter also known is separators to make an array from small string values. These symbols which are called delimiters are(‘,’,’-’,’/’), etc which split a string of your choice.

The explode function has three parameters two of them is mandatory and one of them is optional
1.delimiter or separator:
This parameter actually specifies the point or position on which the string will split for example when the separator found in the string that will be the end of the element fo the array and then start new element of the array
2.the string

This is the original string which we want to split into a small string to make an array.


This parameter is optional which show the number of the array elements.it may be  any integer(positive or negative or zero)


When a positive parameter is passed than the number of array’s element is the same is the number


if the negative parameter is passed then the last n string will be trimmed out


If zero parameter is passed then the return array has only one element mean the whole string.

Return type:

The return type of explode function is array it returns the array which created by explode function

For example:


implode and explode function in php



in the above tutorial, we have been learned the two popular concepts implode vs explode function in PHP. PHP implode function actually joins the array element into a string know as “array to string” while PHP explode split a string to an array known as “string to array” functions.

For tutorial click the following links

1. How to create a simple contact form with PHP?

2. How PHP send email from an application using PHPMailer

3.  How  Php Create Pdf  Files From Html / Mysql