亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Why is laravel5.2 query result not a two-dimensional array?
曾經(jīng)蠟筆沒有小新
曾經(jīng)蠟筆沒有小新 2017-06-06 09:54:43
0
2
951
$res=DB::select('select * from qq');
var_dump($res);

$res=DB::table('qq')->get();
var_dump($res);

Why is a one-dimensional array obtained in the picture after querying in these two ways? Why are there objects in one-dimensional arrays? What we get using native query is a two-dimensional array. Why is the result not a two-dimensional array?

曾經(jīng)蠟筆沒有小新
曾經(jīng)蠟筆沒有小新

reply all(2)
阿神

The following is Laravel 5.4 version, because I have not used Laravel 5.2 version.

Run the native SQL query and get a result set in the form of an array. See the documentation for details.

$res = DB::select('select * from qq');
dd($res);

/*
 * array:5 [▼
    0 => {#388 ?}
    1 => {#399 ?}
    2 => {#400 ?}
    3 => {#401 ?}
    4 => {#402 ?}
    ]
 */

Use the Query Builder to run the SQL statement and get a Collection object. See the documentation for details.

$res = DB::table('qq')->get();
dd($res);

/*
 * Collection {#398 ▼
      #items: array:5 [▼
        0 => {#399 ?}
        1 => {#400 ?}
        2 => {#401 ?}
        3 => {#402 ?}
        4 => {#403 ?}
      ]
  }
 */

  • What you get when you run a native SQL statement is a one-dimensional array wrapped in objects, not a two-dimensional array.

  • What you get using the query constructor is a Collection object, which is also a one-dimensional array wrapping each object. So why return the Collection object, because it has many useful and elegant methods built in. Just like Eloquent returns Collection objects by default.

淡淡煙草味
//返回?cái)?shù)組 laravel 默認(rèn)返回的為對(duì)象
$res=DB::table('qq')->get()->toarray;
dump($res);
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template