我正在尝试获取集合中最后一个元素的属性。我尝试了:
有什么想法吗?
end($collection)->getProperty()
and
$collection->last()->getProperty()
无效,
这告诉我我试图在布尔类型上使用getProperty()
方法。
/**
* Get legs
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getLegs()
{
return $this->aLegs;
}
public function getLastlegdate()
{
$legs = $this->aLegs;
return $legs->last()->getStartDate();
}
有什么想法吗?
$collection
里面有元素吗?在空数组上end()
会返回false
。 - aquemini$collection->last();
- malcolm