What is the difference between explode() and implode() function?

Last updated 1 year, 10 months ago | 825 views 75     5

Tags:- PHP

 PHP | implode() and explode() function

implode() function is use to convert an array into a string where as explode() function is used to convert an string into an array



The implode() function returns a string from elements of an array. It takes an array of strings and joins them together into one string using any delimiter.

$arr = array('Hello','World!','Beautiful','Day!');
echo implode(" ",$arr);

// output will be: Hello World! Beautiful Day!


The explode() function in PHP allows us to splits a string into an array by string. Using the explode() function we will create an array from a string.


$str = "Hello world. It's a beautiful day.";
print_r (explode(" ",$str));


// output will be: 

Array ( [0] => Hello [1] => world. [2] => It's [3] => a [4] => beautiful [5] => day. )

The explode() function breaks a string into an array, but the implode function returns a string from the elements of an array.