Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个实体订单,它将供应商保存在 Arraycollection 中。在我的控制器中,我想检查这个 arraycollection 是否为空:
$suppliers = $order->getSuppliers();
我试过了:
if(!($suppliers)) {} if(empty($suppliers)) {}
有任何想法吗?
Doctrine ArrayCollection 有一种方法可以满足isEmpty您的需求。
isEmpty
if ($suppliers->isEmpty()) { }
在这里查看它的文档
您还可以使用count()PHP 函数:
count()
if (count($suppliers) < 1) { }