4

i have an array i want to join into a string using comma(,) separated values. is there a function similar on the lines of join function in php?

1
  • 1
    As it happens, PHP defines an alias for the implode function everyone is talking about. That alias is called join. Commented Jan 12, 2010 at 20:28

5 Answers 5

6

Try implode(', ', $array) function.

Sign up to request clarification or add additional context in comments.

2 Comments

not sure why that answer is better than mine... can someone please tell me?
@Jacob Relkin: It was first unswer
3

You can use implode.

$string = implode( ',', $array );

Likewise, you can then return the string to an array with explode.

$array = explode( ',', $string );

Comments

3

Say hello to the implode function in PHP:

$array = array('lastname', 'email', 'phone');
$comma_separated = implode(",", $array);

Comments

3

You can use the implode function :

$your_array = array('a', 'b', 'c', 'd');
$string = implode(',', $your_array);
echo $string;

Will get you this output :

a,b,c,d

Note that ',' have been added between the array's elements, and not at the beginning nor the end of the string.

Comments

2

implode

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.