如何将以下输出合并为单行并存储在单个变量
中我有以下输出
THICKNESS: .1875ItemID: VSG-10
THICKNESS: .1875ItemID: VSG-7
THICKNESS: .1875ItemID: VSG-8
THICKNESS: 10ItemID: VSG-22
THICKNESS: 10ItemID: VSG-23
THICKNESS: .1875ItemID: VSG-3
THICKNESS: .1875ItemID: VSG-6
THICKNESS: .1875ItemID: VSG-4
THICKNESS: .1875ItemID: VSG-27
以下是我用于获取上述输出的代码
$d = explode(',', $row['ItemDesc']);
$c = explode(',', $row['ItemIDgroup']);
foreach($d as $k => $v)
{
$d2 = explode(' ',$v);
$output = "THICKNESS: " . $d2[1] ."ItemID: ". $c[$k];
echo $output;
echo"<br/>";
}
我想最终喜欢并希望存储在单个变量中
THICKNESS: .1875ItemID: VSG-10, THICKNESS: .1875ItemID: VSG-7,THICKNESS: .1875ItemID: VSG-8, ....
答案 0 :(得分:3)
看起来您可以将预期的字符串添加到数组中。
$final[] = "THICKNESS" . $row["ItemDesc"] . "ItemID: " . $row["ItemIDgroup"];
然后在最后做$output = implode(', ', $final);