简体   繁体   中英

Paste values from array into string

If have this array:

$a = array("one", "two", "three");

I want to transform this into this string:

$s = "one, two, three";

Is there a paste function in PHP?

Eg:

$s = paste($a, sep=", ");

使用爆破

$s = implode(', ',$a);
$a = array("one", "two", "three");

foreach($a as $value) {
   $string = $string . ($value != '' ? '' : ', ') . $value;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM