基本上,如果我有一个DoctrineCollection的DoctrineRecord对象,并想将其转换为数组,我可以使用:
$collection->toArray() 要么 $collection->getData()
但我不明白这两种方法之间的区别.
我正在尝试获取集合中最后一个元素的属性。我试过了
end($collection)->getProperty()
Run Code Online (Sandbox Code Playgroud)
和
$collection->last()->getProperty()
Run Code Online (Sandbox Code Playgroud)
没有办法
(告诉我我正尝试getProperty()在布尔值上使用)。
/**
* Get legs
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getLegs()
{
return $this->aLegs;
}
public function getLastlegdate()
{
$legs = $this->aLegs;
return $legs->last()->getStartDate();
}
Run Code Online (Sandbox Code Playgroud)
知道为什么吗?