製品の配列を作成日でソートしようとする次のコードがあります。
private function sortProductsByDate(Product $a, Product $b)
{
if ($a->getCreated() == $b->getCreated()) {
return 0;
}
return ($a->getCreated() < $b->getCreated()) ? -1 : 1;
}
/**
* Get the most 4 recent items
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getMostRecentItems()
{
$userMostRecentItems = array();
$products = $this->getProducts();
usort($products, "sortProductsByDate");
foreach ($this->getProducts() as $product) {
ladybug_dump($product->getCreated());
}
$mostRecentItems = $this->products;
return $this->isLocked;
}
なぜこれが私にこのエラーを与えるのですか:
Warning: usort() expects parameter 1 to be array, object given
アイデア?