如何在sprintf PHP中添加逗号分开?

  • 本文关键字:添加 sprintf PHP php
  • 更新时间 :
  • 英文 :

我有一个这样的循环:
foreach ($imported_data as $index => $product_data) {
$Str = sprintf('"%s"',$imported_data[$index][0]);
$result = str_replace('""', '","', $Str);
echo $result;
}

结果是:

"200728J70JNY08""200728JQ05Y4S4""200730QWVD1DDQ""200728H2QS7M9Y"

我希望我的字符串是:

"200728J70JNY08","200728JQ05Y4S4","200730QWVD1DDQ","200728H2QS7M9Y"

试一试:

$Str = '';
foreach ($imported_data as $index => $product_data) {
$Str .= sprintf('"%s"',$imported_data[$index][0]);
}
$result = str_replace('""', '","', $Str);
echo $result;

最新更新