如何将Laravel框架中的查询数据集转换为数组?

2026-04-01 07:210阅读0评论SEO教程
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计149个文字,预计阅读时间需要1分钟。

如何将Laravel框架中的查询数据集转换为数组?

方法一:直接查询数据库sqlreturn DB:table('game_matchperiod') ->select('starttime') ->where('Type', $type) ->get() ->toArray();

方法二:对象转数组phppublic function objToArr($object) { // 先编码成json字符串,再解码 return json_decode(json_encode($object), true);}

方法一:

return DB::table('game_matchperiod')->select('starttime')->where('Type',$type)->get() ->map(function ($value) {return (array)$value;})->toArray();

方法二:

public function objToArr($object) { //先编码成json字符串,再解码成数组 return json_decode(json_encode($object), true); }

以上这篇laravel框架查询数据集转为数组的两种方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持易盾网络。

阅读全文
标签:两种

本文共计149个文字,预计阅读时间需要1分钟。

如何将Laravel框架中的查询数据集转换为数组?

方法一:直接查询数据库sqlreturn DB:table('game_matchperiod') ->select('starttime') ->where('Type', $type) ->get() ->toArray();

方法二:对象转数组phppublic function objToArr($object) { // 先编码成json字符串,再解码 return json_decode(json_encode($object), true);}

方法一:

return DB::table('game_matchperiod')->select('starttime')->where('Type',$type)->get() ->map(function ($value) {return (array)$value;})->toArray();

方法二:

public function objToArr($object) { //先编码成json字符串,再解码成数组 return json_decode(json_encode($object), true); }

以上这篇laravel框架查询数据集转为数组的两种方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持易盾网络。

阅读全文
标签:两种