![]() |
VOOZH | about |
The implode() is a built-in function in PHP and is used to join the elements of an array. implode() is an alias for PHP | join() function and works exactly same as that of join() function.
If we have an array of elements, we can use the implode() function to join them all to form one string. We join array elements with a string. Just like join() function , implode() function also returns a string formed from the elements of an array.
Syntax:
string implode(separator,array)Parameters: The implode() function accepts two parameters out of which one is optional and one is mandatory.
Note: The separator parameter of implode() is optional. However, it is recommended to always use two parameters for backwards compatibility.
Return Type: The return type of implode() function is string. It will return the joined string formed from the elements of the array.
Examples:
Input : implode(array('Geeks','for','Geeks')
Output : GeeksforGeeks
Input : implode("-",array('Geeks','for','Geeks')
Output : Geeks-for-Geeks
Below program illustrates the working of implode() function in PHP:
In this example, the implode() function is used to join the elements of an array into a single string without specifying any separator. Since no separator is provided, the elements will be joined directly, one after the other.
GeeksforGeeks
In this example, the implode() function is used to join the elements of an array into a single string with a specified separator. Here, the separator is "-", so the elements will be joined with dashes between them.
Geeks-for-Geeks