php - 如何从外部数组获取内部数组

标签 php arrays json laravel api

我想从外部数组中提取一个数组。

我的结果

enter image description here

我想删除数组的圆圈符号

{
"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"
        }
    ],   
]

}

这是我的数组输出结果。

我的 Controller 代码

 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
                    ]); 

最佳答案

使用 first() 根据您想要删除额外数组引号的图像获取一个对象,因此

$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)
                    ->first();

希望对你有帮助!

关于php - 如何从外部数组获取内部数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53532647/

相关文章:

php - AJAX 登录表单重新加载页面

java - BufferedImages 数组错误?

javascript - 获取数组作为 ScriptEngine.eval() 的结果

android - 获取recyclerview位置并在点击时传递对象

javascript - 我的 session 在到达设定时间之前就结束了...?

php - Laravel 原始查询并包含模型关系

arrays - 在 mongodb 数组中查找最接近的值

android - 通过 https 发送和接收 json 消息

java - JSON 解析错误 - 发布 json 时数据类型错误

PHP mkdir() 在浏览器中不工作