n92
n92

Reputation: 7602

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?

Upvotes: 8

Views: 6205

Answers (2)

Your Common Sense
Your Common Sense

Reputation: 157981

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
}

Upvotes: 21

mark-cs
mark-cs

Reputation: 4707

You want the empty() function, here's the documentation of the empty function http://php.net/manual/en/function.empty.php

Upvotes: 11

Related Questions