【发布时间】:2019-05-01 03:21:48
【问题描述】:
我想从外部数组中拉出一个数组。
我的结果
我要删除数组的圆圈符号
{
"Success": "1",
"Message": "Subtopic Wise Questions...",
"Subtopic Questions": [
[
{
"id": "93",
"topic_id": "36",
"name": "Cell membrane and organelle",
"created_at": "2018-08-29 23:06:34",
"updated_at": "2018-08-29 23:06:34",
"q_count": "127"
}
],
]
}
这是我的数组输出结果。
我的控制器代码
foreach($findid as $v)
{
$count[] = DB::table('questions')
->join('subtopics', 'subtopics.id', 'questions.subtopic_id')
->select('subtopics.*', DB::raw('count(questions.id) as q_count'))
->where('subtopic_id', $v)
->get();
}
return response([
'Success' => "1",
'Message' => "Subtopic Wise Questions...",
'Subtopic Questions' => $count
]);
【问题讨论】:
-
使用
$count而不是$count[] -
使 foreach 循环通过 Subtopic Questions->Subtopic Questions
-
@JigneshJoisar 如果我使用 $count 它只返回结果的第一列。
-
在我看来,您应该尝试一次获取所有必需的行,而不是每次获取一个。
标签: php arrays json laravel api