【问题标题】:Multidimensional array from query into string gives Array to string conversion notice多维数组从查询到字符串给出数组到字符串转换的通知
【发布时间】:2015-02-12 23:27:51
【问题描述】:

我正在使用 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循环和之后。您需要说明是哪一行给出了错误。
  • 在 while 循环之前只有 DB 凭据,错误出现在 '.$datapiece["id"].' 上 foreach 循环内的行上,在while 循环我有一个 $header 变量,我将它插入到要发送的 xml 中,如下所示: $xml = $header.$string $array 的 var 转储显示以下内容: string(85) "Array 1 2 "
  • $string 是什么?请print_r($datapiece);

标签: php xml string curl multidimensional-array


【解决方案1】:
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>

【讨论】:

  • 你为什么发布这个作为答案?.. 你为什么要覆盖 $data 变量?
  • 那是个错误。我不应该覆盖 $data。 $数据 = $数据。 '....应该有一个不同的名字。这解决了问题。我真的很感谢你抽出时间来帮助我。和stackoverflow.com/questions/12959196/…是一样的情况@
猜你喜欢
  • 2016-03-07
  • 2017-01-31
  • 2014-04-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多