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?
not sure why that answer is better than mine... can someone please tell me?
Jacob Relkin
2010-01-12 22:02:10
@Jacob Relkin: It was first unswer
Ivan Nevostruev
2010-01-12 22:05:26
+1
A:
You can use implode.
$string = implode( ',', $array );
Likewise, you can then return the string to an array with explode.
$array = explode( ',', $string );
Jacob Relkin
2010-01-12 20:23:35
+1
A:
Say hello to the implode function in PHP:
$array = array('lastname', 'email', 'phone');
$comma_separated = implode(",", $array);
Parrots
2010-01-12 20:24:22
+1
A:
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.
Pascal MARTIN
2010-01-12 20:25:12