为什么laravel返回一个信息过多的查询。
为什么要查询:
DB::table('emails')->where('sent', '0')->get();
生成此stdClass条目:
["email"]=> string(21) "webmaster@example.com"
取而代之的是:
["email"]=> "webmaster@example.com"
$collection = DB::table('emails')->where('sent', '0')->get();
$array = $collection->toArray();
get()
每次都返回一个对象集合。该集合中可能有0个或多个对象,具体取决于查询的结果。所以,您必须使用toArray()
将它们转换为数组。
使用此:
$data = DB::table('emails')->where('sent', '0')->get()->toArray();
print_r($data);