PHP无法将数组操作为数组(implode,echo key),数组到字符串的转换

时间:2017-02-09 11:03:19

标签: php arrays

我有一个数组,根据所有权利,似乎是一个数组:

var_dump($arr);

给出这个:

array(3) {
  ["query"]=>
  string(47) "select * from `sessions` where `id` = ? limit 1"
  ["bindings"]=>
  array(1) {
    [0]=>
    string(40) "beec3e058d85062452f025e1f2156f2fefdf87ea"
  }
  ["time"]=>
  float(0.94)
}   

但是,我无法将其作为数组进行操作。

echo implode("\n", $arr);

生成堆栈跟踪和'数组到字符串转换'我的Laravel应用程序出错。问题是什么,我怎样才能做到这一点" array"会接受implodeecho $arr['query']等操作吗?

1 个答案:

答案 0 :(得分:1)

你不能对这个特定的数组进行内爆,因为它的值中有一个数组。如果你有一个只包含标量值的数组,你就可以了。

$arr ['query']有效,因为它是一个字符串,不需要转换。

我假设你想要一个数组的字符串表示。你为什么不用它:

var_export($arr, true)