dpnvrt3119 2016-02-26 10:33
浏览 156

Eloquent(Laravel)结果为数组

I am trying to get result from Eloquent (Laravel 4.2) into simple array, so I con make array_diff.

In documentation I found all() function, which gives result to array, but the are also things I cant have, because of array_diff.

I have :

$curCentres = Doccentre::where('r_document', $document)->select('r_id')->get()->all();

but this return something like:

array(2) { 
    [0]=> object(Doccentre)#1125 (20) {
         ["table":protected]=> string(9) 
            "doccentre" ["primaryKey":protected]=> string(4) 
            "r_id" ["timestamps"]=> bool(false) 
            ["connection":protected]=> NULL 
            ["perPage":protected]=> int(15) 
            ["incrementing"]=> bool(true) 
            ["attributes":protected]=> array(1) {
                 ["r_id"]=> string(1) "1" 
            } 
            ["original":protected]=> array(1) { 
                ["r_id"]=> string(1) "1" 
            }
            ["relations":protected]=> array(0) { } 
            ["hidden":protected]=> array(0) { } 
            ["visible":protected]=> array(0) { } 
            ["appends":protected]=> array(0) { } 
            ["fillable":protected]=> array(0) { } 
            ["guarded":protected]=> array(1) { 
                [0]=> string(1) "*" 
            } 
            ["dates":protected]=> array(0) { } 
            ["touches":protected]=> array(0) { } 
            ["observables":protected]=> array(0) { } 
            ["with":protected]=> array(0) { } 
            ["morphClass":protected]=> NULL 
            ["exists"]=> bool(true) 
        } 
    [1]=> object(Doccentre)#1124 (20) { 
        ["table":protected]=> string(9) 
        "doccentre" ["primaryKey":protected]=> string(4) 
        ....
} 

All I need is :

array(2) { [0]=> string(1) "1" [1]=> string(1) "2" } 

Is there any way to get it? I also tried toArray(), but it makes only errors.

  • 写回答

1条回答 默认 最新

  • drk7700 2016-02-26 10:38
    关注

    You could use lists to retrieving a list of column values:

    $curCentres = Doccentre::where('r_document', $document)->lists('r_id');
    

    Hope this helps.

    评论

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序