【发布时间】:2021-01-13 17:59:36
【问题描述】:
当我尝试时:
echo $response;
输出是 LIKE(类似):
{
"identity": {
"result": [
{
"name" = "Dilan",
"place_id" = 1
},
{
"name" = "Milea",
"place_id" = 1
}
]
}
},
{
"identity": {
"result": [
{
"name" = "Ariel",
"place_id" = 2
},
{
"name" = "Noah",
"place_id" = 2
}
]
}
}
不,当我尝试回显 $response['identity'] 时,输出仅显示第一个数组,我对 $response 的所有操作仅适用于第一个数组,我无法对第二个数组执行任何操作数组。
我想要的是将所有数组输出合并到 1 个数组中,如下所示:
{
{
"identity": {
"result": [
{
"name" = "Dilan",
"place_id" = 1
},
{
"name" = "Milea",
"place_id" = 1
}
]
}
},
{
"identity": {
"result": [
{
"name" = "Ariel",
"place_id" = 2
},
{
"name" = "Noah",
"place_id" = 2
}
]
}
}
}
这里是我的控制器
谢谢!非常需要你的帮助^^
【问题讨论】:
-
你不需要合并 .您需要遍历
$response并执行任务,因为如果合并则它将与(as you mention above merge code)之前相同 -
btw $response 的输出是字符串,当我尝试转换为像 $test = json_decode($response, true); 这样的数组时dd($测试);然后,它只执行只转储第一个数组的第一个数组
-
我认为
echo $response;不会输出数组。你如何构建“数组”? -
它不是一个数组,而是一个 json_encoded
-
@executable 当我尝试 dd($response);不做json_decode,输出还是只有第一个数组