Search code examples
phparraysphp4

How do I determine if an array is empty in PHP?


I want to check that an array has no values or that the values in the array are empty. Can someone explain how to do this?


Solution

  • Someday I've learned very smart solution here on SO

    if(!array_filter($array)) {
      //array contains only empty values
    }
    

    or even smarter one (if applicable):

    if(!array_filter($array,'trim')) {
      //array contains only empty values
    }