Before few days we have a requirement to make comma separated string from php array.
To do so we have used “implode()” of php, which joins array elements with a string.
“implode(separator, array)” is supporting in PHP 4, PHP 5 and it has two arguments.
First one is a separator – A string which is used to put between the array elements. Default it is “”. And this argument is optional.
Second one is an array – An array to join to a string separator. And this argument is required.
Now here is an example to make comma separated string from array using implode().
$array_elements = array("First", "Second", "Third", "Fourth", "Fifth"); $comma_separated_string = implode(', ', $array_elements); echo "<br />Comma Separated String:<br />" . $comma_separated_string;
Try it and hope this will help you.