Check if ArrayCollection is empty

后端 未结 2 955
不知归路
不知归路 2021-02-02 08:24

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->get         


        
相关标签:
2条回答
  • 2021-02-02 09:06

    You can also use the count() PHP function:

    if (count($suppliers) < 1) { }
    
    0 讨论(0)
  • 2021-02-02 09:28

    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

    0 讨论(0)
提交回复
热议问题