开发者

join function for a php array

开发者 https://www.devze.com 2022-12-16 08:24 出处:网络
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

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

0

精彩评论

暂无评论...
验证码 换一张
取 消