我有以下代码,它尝试按产品的创建日期对产品数组进行排序:
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
想法?