How to make comma separated string from php array?

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.

Advertisements

Speak Your Mind

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: