PHP Implode Explode Example


PHP implode() and explode() are the couple of popularly used string functions. Both are used to convert a string or array data from one another and these are a complement to each other.

PHP Implode

implode() function accepts a separator and an array as its parameter. It combines each of the array elements whereas the combined elements are separated with the separator. For example,

This program will return combined array elements separated by the (|) symbol. There are no strict rules for the arguments order of this function. For example, we can use implode as like as,

PHP Explode

On the other hand, explode() is to split the string into an array of elements with respect to the given separator. explode() accepts separator and a string as its argument.

PHP explode() Example

This program accepts the resultant string data of implode example we have seen above. As we given the same separator string (|), explode() splits string data and reproduce the original array we have given for imploding. The output of this program will explode

( ) is used as an alternative for split(), a deprecated PHP function. We have seen the reason for why split() is deprecated.

PHP explode() accepts a third optional argument limit to set target length or boundary for performing explode operation. explode() will take entire string if nothing is specified a a limit.

Explode within Limit

this will return,


  • The limit argument should be a positive integer.
  • As like implode(), we cannot change the order of arguments for the explode() function.

Leave A Reply

Your email address will not be published.