What are Implode and Explode functions?
Ans: The implode() function returns a string from the elements of an array.
It takes an array of strings and joins them together into one string using a delimiter (string to be used between the pieces) of your choice.
The implode function in PHP is easily converting as “array to string”, which simply means that it takes an array and returns a string. It rejoins any array elements and returns the resulting string, which may be put in a variable.
Suppose you have an array like this $arr = Array (“A”,”E”,”I”,”O”,”U”);
and you wish to combine it into a string, by putting the separator ‘-‘ between each element of the array.
How to do that?
$str = implode(“+”,$arr);
So your resulting string variable $str will contain:
A+E+I+O+U
implode (separator, array)
<html>
<body>
<h3>Implode Function Example</h3>
<?php
$arr=array ('I','am','software','developer');
echo implode(" ",$arr);
?>
</body>
</html>
The explode() function breaks a string into an array.
Example:
<?php
$str = "I am software developer";
print_r (explode(" ",$str));
?>