In this article, learn how to use PHP Implode() function.The Implode() function is a predefined inbuilt PHP function. We can form a string by joining the components of an array with the help of the PHP implode function. The implode() function creates a string from components of an array utilizing a delimiter of our choice. The implode() function acknowledges two parameters out of which one is optional and one is mandatory.
Let's learn those parameters.
This is an optional parameter and is of string type. The values of the array will be join to form a string and will be separated by the separator parameter provided here.
The array whose value is to be joined to form a string.
<?php $arr = array ('Welcome','To','Tutorials','Point'); $comma_separated = implode(" , ", $arr); $hyphen_separated = implode(" - ", $arr); echo $comma_separated"\n" ; echo implode(" ",$arr)"\n"; echo $hyphen_separated; ?>
Welcome , To , Tutorials , Point Welcome To Tutorials Point Welcome - To - Tutorials - Point
In the first expression, we have used a comma "," as a separator to form string. In the second expression, we have used space " " as a separator to demonstrate the implode function.