从查询到字符串的多维数组给出数组到字符串的转换通知

Multidimensional array from query into string gives Array to string conversion notice

我正在使用 CURL 传递根据查询结果创建的 xml 字符串。

字符串创建如下:

while ($row = mysqli_fetch_assoc($data_to_insert)) {$data[ ] = $row;}

foreach($data as $datapiece)
{
 $data = data.'
 <field>
 <id>'.$datapiece["id"].'</id>
 <value>'.$datapiece["value"].'</value>

为什么我会收到数组到字符串转换的通知?

while ($row = mysqli_fetch_assoc($data_to_insert)) {$data[ ] = $row;} --->    $data is array in here

foreach($data as $datapiece)
{
$data = data.' ----> data is a string in here IT SHOULDN'T BE OVERWRITING PREVIOUS VARIABLE, VARIABLE NEEDS TO BE GIVEN A DIFFERNT NAME
<field>
<id>'.$datapiece["id"].'</id>
<value>'.$datapiece["value"].'</value>