close

Q:

Hi there,

I have a large SQL statement that I am executing like so...

 

$result = DB::select($sql);

 

I'd like the result to be an array - but at the moment it returns a structure like so, an array with Objects...

 

Array
(
    [0] => stdClass Object
    (
        [field] => 6
    )
...etc...

 

Any advice much appreciated...

 

A:

使用->toArray()這個function

UPDATE: Indeed it still returning objects inside, as @pixelgremlins said, working using collect($data)->map(function($x){ return (array) $x; })->toArray()

--

轉自 https://laravel.io/forum/10-14-2014-dbselect-toarray

--

 

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 dizzy03 的頭像
    dizzy03

    碎碎念

    dizzy03 發表在 痞客邦 留言(0) 人氣()