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?
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?
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
Order::hasSuppliers(): bool
method, which returns $this->suppliers->isEmpty()
. This way, if someday you decide to migrate from Doctrine, you will need to change your code in only one place. –
Antigen You can also use the count()
PHP function:
if (count($suppliers) < 1) { }
© 2022 - 2024 — McMap. All rights reserved.