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?
Asked
Active
Viewed 6,022 times
8
-
What do you mean by "array values is empty"? Useful functions/constructs: `is_array`, `count`, `empty`, `isset`. It all depends on what *exactly* you're trying to test. – Alin Purcaru Apr 13 '11 at 13:02
-
here is an array with no values only keys .i used count and empty but those functions are saying array has values .Array ( [delegate_title] => [delegate_firstname] => [delegate_lastname] => [delegate_jobtitle] => [delegate_email] => [delegate_phone] => [is_bringing_own_laptop] => ) – n92 Apr 13 '11 at 13:07
2 Answers
21
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
}

Your Common Sense
- 156,878
- 40
- 214
- 345
-
-
1
-
-
-
array_filter is really handy! never used it before today, but it solves my problem! thank you! – AO_ Nov 13 '12 at 13:39
11
You want the empty()
function, here's the documentation of the empty function http://php.net/manual/en/function.empty.php

mark-cs
- 4,677
- 24
- 32