簡體   English   中英

雄辯的(Laravel)結果數組

[英]Eloquent (Laravel) result to array

我正在嘗試將Eloquent(Laravel 4.2)的結果轉換為簡單數組,因此我選擇了array_diff

在文檔中,我找到了all()函數,該函數將結果提供給array,但是由於array_diff ,我也無法做到這一點。

我有 :

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

但這返回類似:

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) 
        ....
} 

我需要的是:

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

有什么辦法嗎? 我也嘗試過toArray() ,但它只會出錯。

您可以使用lists來檢索列值的列表:

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

希望這可以幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM