2017-07-06 77 views
1

是否有一種方法可以從集合項目中選擇唯一值?
例如:集合選擇集合唯一值上的項目

{ 
     "identifier": 1, 
     "name": "Robert", 
     "lastname": "Brown", 
     "age": "30" 
    }, 
    { 
     "identifier": 2, 
     "name": "Robert", 
     "lastname": "Brown", 
     "age": "30" 
    } 

在此集合,我想是因爲他們有相同的名字,姓氏和年齡只得到兩個項目之一。

+1

我們希望你嘗試自己**編寫的代碼可用**。在[**做更多的研究**之後](https://meta.stackoverflow.com/q/261592/1011527)如果你有問題**發佈你已經嘗試過**的**清楚的解釋不工作**並提供[最小,完整和可驗證示例](http://stackoverflow.com/help/mcve)。閱讀[如何問](http://stackoverflow.com/help/how-to-ask)一個很好的問題。請務必[參觀](http://stackoverflow.com/tour)並閱讀[this](https://meta.stackoverflow.com/q/347937/1011527)。 –

+0

把它當作一個普通的數組,寫一些代碼,如果你有問題,請發佈你的嘗試 –

回答

2

有很好的方法laravel

$unique = $collection->unique('name'); 

    $unique->values()->all(); 

official laravel docs