join function for a php array
i have an array i want to join into a string using comma(,) 开发者_JS百科separated values. is there a function similar on the lines of join function in php?
Try implode(', ', $array)
function.
You can use implode.
$string = implode( ',', $array );
Likewise, you can then return the string to an array with explode.
$array = explode( ',', $string );
Say hello to the implode function in PHP:
$array = array('lastname', 'email', 'phone');
$comma_separated = implode(",", $array);
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.
implode
精彩评论