Check if ArrayCollection is empty
I have an Entity Order which hold Suppliers in an Arraycollection. In my controller i want to check if this arraycollection is empty: $suppliers = $order->getSuppliers(); I tried: if(!($suppliers)) {} if(empty($suppliers)) {} Any ideas? Ken Hannel Doctrine ArrayCollection has a method isEmpty that will do what you are looking for. if ($suppliers->isEmpty()) { } Take a look at the documentation for it here You can also use the count() PHP function: if (count($suppliers) < 1) { } 来源: https://stackoverflow.com/questions/17643047/check-if-arraycollection-is-empty