PHP | implode() Function
The implode() is a builtin 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 basically 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 parameter out of which one is optional and one is mandatory.
- separator: 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. This is optional, if not provided the default is “” (i.e. an empty string).
- array: The array whose value is to be joined to form a string.
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 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:
<?php // PHP Code to implement join function $InputArray = array('Geeks','for','Geeks'); // Join without separator print_r(implode($InputArray)); print_r("\n"); // Join with separator print_r(implode("-",$InputArray)); ?> |
Output:
GeeksforGeeks Geeks-for-Geeks
Reference: http://php.net/manual/en/function.implode.php
Recommended Posts:
- Implode an array with jQuery/JavaScript
- How to call a function that return another function in JavaScript ?
- How to get the function name inside a function in PHP ?
- How to get the function name from within that function using JavaScript ?
- p5.js | hex() function
- p5.js | nf() Function
- D3.js | d3.min() function
- PHP | abs() Function
- D3.js | d3.rgb() Function
- PHP | end() Function
- PHP | each() Function
- p5.js | int() function
- p5.js | value() Function
- CSS | hsl() Function
- PHP | pow( ) Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



