Here we show how you can transform a string in an array and an array change in a string. PHP provide to built in functions for these purpose implode() and explode() .
Implode() – implode() built in function use to change an array into a string.
Below is syntax
implode (separator, array)
We can transform a string from an array using implode() method. We just need to pass two parameter, One is array of strings and second is a delimiter of your response string.
The delimiter is used to joins them together into one string.
Below is example
";
print_r($arr);
echo $str;
?>
OUTPUT
Explode()- explode() built in function use to change a string into an array.
Below is syntax:
explode (separator,string,limit)
Explode() function break a string into smaller text with each break occurring at the same symbol. This symbol is known as the separator(delimiter). Using the explode() method you can create an array from a string. The explode() function breaks a string into an array.
Below is example
";
print_r($arr);
?>
OUTPUT
You can split string into array using explode() method, and vise-versa easily using implode() method.
I hope this article helps you.
Thanks for visiting Inflay.com .