uniqueBy() публичный статический Метод

Example: $a = new stdClass(); $a->name = 'bob'; $b = new stdClass(); $b->name = 'bob'; $array = [$a, $b]; $result = Arrays::uniqueBy($array, 'name'); Result: Array ( [0] => $b )
public static uniqueBy ( array $elements, $selector ) : array
$elements array
$selector
Результат array
Пример #1
0
 /**
  * @test
  */
 public function shouldReturnObjectsUniqueByNestedField()
 {
     //given
     $category = new Category(array('name' => 'cat1'));
     $product1 = new Product(array('name' => 'bob'));
     $product1->category = $category;
     $product2 = new Product(array('name' => 'john'));
     $product2->category = $category;
     $array = array($product1, $product2);
     //when
     $uniqueByName = Arrays::uniqueBy($array, 'category->name');
     //then
     Assert::thatArray($uniqueByName)->hasSize(1);
 }