Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 219
ChrisS Avatar asked Jul 14 '13 19:07

ChrisS


1 Answers

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

like image 144
Ken Hannel Avatar answered Sep 30 '22 05:09

Ken Hannel