Laravel-获取没有表列名的数据库结果 [英] Laravel - get DB result without table column name

查看:127
本文介绍了Laravel-获取没有表列名的数据库结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想只使用Laravel 4.2中的表列名称而不包含值的结果.例如,

I wanted to have the result with only the values not with the table column name in Laravel 4.2. For example,

$recs = DB::table('table_name')
        ->select('id', 'title')
        ->get();

结果是

array(2) {
  [0]=>
  object(stdClass)#863 (2) {
    ["id"]=>
    int(2)
    ["title"]=>
    string(8) "my title"
  }
  [1]=>
  object(stdClass)#862 (2) {
    ["id"]=>
    int(3)
    ["title"]=>
    string(10) "my title 2"
  }
}

但是我只希望结果而不是列名,例如

but I want to have only the result NOT the column name, like

[
  2,
  "my title"
],
[
  3,
  "my title 2"
]

是的,我可以通过循环结果并创建没有列名的新数组来实现.但是,有什么方法可以使用Laravel以这种方式获得结果吗?

yes, I can make it by looping the result and make new array without column name. But is there are any way to get the result in this fashion using Laravel ?

推荐答案

尝试

$recs = DB::table('table_name')->pluck('id', 'title');
dd($recs->all());

这篇关于Laravel-获取没有表列名的数据库结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆