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?
5 Answers
2 Comments
Jacob Relkin
not sure why that answer is better than mine... can someone please tell me?
Ivan Nevostruev
@Jacob Relkin: It was first unswer
Say hello to the implode function in PHP:
$array = array('lastname', 'email', 'phone');
$comma_separated = implode(",", $array);
Comments
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.
join.